Skip to content

Instantly share code, notes, and snippets.

@alik472
Last active May 6, 2019 13:38
Show Gist options
  • Save alik472/ebf7a689558402393b5122b08893177c to your computer and use it in GitHub Desktop.
Save alik472/ebf7a689558402393b5122b08893177c to your computer and use it in GitHub Desktop.
JS days - Part 3 - Scope Chain
function b (){
// reference outer environment
console.log(myVar, 'myVar inside function b')
}
function a(){
var myVar=2
console.log(this===global)
console.log(myVar,'myVar inside function a')
console.log(this.myVar,'this.myVar inside function a')
b()
}
var myVar=1
a()
console.log(a.prototype.__proto__)
// console.log(Object.keys(a),'keys')
// function dir(object) {
// stuff = [];
// for (s in object) {
// stuff.push(s);
// }
// stuff.sort();
// return stuff;
// }
// console.log(dir(a),'dir')
// the problem is function b sits
// lexically in the global environment
// where the funciton is physically written
// that whole is chain called scope chain
//SCOPE - where your variable is in your code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment