Skip to content

Instantly share code, notes, and snippets.

@Daniel-Xu
Created May 14, 2014 07:09
Show Gist options
  • Select an option

  • Save Daniel-Xu/02b5debeb1981ed8a8ea to your computer and use it in GitHub Desktop.

Select an option

Save Daniel-Xu/02b5debeb1981ed8a8ea to your computer and use it in GitHub Desktop.
lexical scoping
var y = "glo"
function printy(){
console.log(y)
}
function test(y)
{
var y = "inner"
printy()
function a(){
console.log(y)
}
a()
}
test(1)
@Daniel-Xu
Copy link
Author

The result is:

glo

inner

the outer variable is visible during the definition of function, like function a().

but printy() is invoking, and the scope bind to it is global variable.

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