Last active
May 6, 2019 13:38
-
-
Save alik472/ebf7a689558402393b5122b08893177c to your computer and use it in GitHub Desktop.
JS days - Part 3 - Scope Chain
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 (){ | |
// 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