Skip to content

Instantly share code, notes, and snippets.

@thegreatape
Created September 27, 2010 17:51
Show Gist options
  • Save thegreatape/599474 to your computer and use it in GitHub Desktop.
Save thegreatape/599474 to your computer and use it in GitHub Desktop.
var foo = 'bar';
var a = function(){
console.log(foo);
}
var b = function(){
console.log(foo);
var foo = 'blarg';
}
a()
// 'bar' is logged. no surprises.
b()
// undefined is logged! defining a var *later* in the function
// prevents foo from being looked up in the closure scope
@polotek
Copy link

polotek commented Sep 27, 2010

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment