Skip to content

Instantly share code, notes, and snippets.

@peterbsmyth
Created September 25, 2015 19:56
Show Gist options
  • Save peterbsmyth/63b31be50f9891276eff to your computer and use it in GitHub Desktop.
Save peterbsmyth/63b31be50f9891276eff to your computer and use it in GitHub Desktop.
Scope Chain Example.
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