Skip to content

Instantly share code, notes, and snippets.

@willread
Created October 17, 2013 20:11
Show Gist options
  • Save willread/7031438 to your computer and use it in GitHub Desktop.
Save willread/7031438 to your computer and use it in GitHub Desktop.
Why does foo = "" while obj = {foo: "bar"}?
var getFoo = function(){
var val = "";
$.get(".", function(){
val = {foo: "bar"};
});
return val;
}
var foo = getFoo();
// foo = ""
var getObj = function(){
var obj = {};
$.get(".", function(){
obj.foo = "bar";
});
return obj;
}
var obj = getObj();
// obj = {foo: "bar"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment