Created
May 14, 2014 07:09
-
-
Save Daniel-Xu/02b5debeb1981ed8a8ea to your computer and use it in GitHub Desktop.
lexical scoping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var y = "glo" | |
| function printy(){ | |
| console.log(y) | |
| } | |
| function test(y) | |
| { | |
| var y = "inner" | |
| printy() | |
| function a(){ | |
| console.log(y) | |
| } | |
| a() | |
| } | |
| test(1) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.