Skip to content

Instantly share code, notes, and snippets.

@yorkie
Created May 4, 2014 16:08
Show Gist options
  • Save yorkie/508a6fecfd237e940c05 to your computer and use it in GitHub Desktop.
Save yorkie/508a6fecfd237e940c05 to your computer and use it in GitHub Desktop.
it prints 10 not 20, because javascript use static(lexical) scope for function variable
var x = 10;
function foo() {
console.log(x);
}
(function(func) {
var x = 20;
foo();
})(foo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment