Created
September 25, 2015 19:56
-
-
Save peterbsmyth/63b31be50f9891276eff to your computer and use it in GitHub Desktop.
Scope Chain Example.
This file contains 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
function b(){ | |
console.log(myVar); | |
} | |
function a(){ | |
var myVar = 2; | |
console.log(myVar); | |
} | |
var myVar = 1; | |
a(); | |
// what does b() log? ==> 1 | |
// the containing outer scope of function b is the global scope, because | |
// what matters is where the function is defined, not where it is executed. | |
// It, lexically, is in the scope of the global environment. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment