Last active
January 29, 2019 13:20
-
-
Save jitendra19/831ab63dc78d0b660a1b7692b4e54931 to your computer and use it in GitHub Desktop.
JS questions
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 foo() { | |
console.log(abc) | |
} | |
function goo() { | |
var abc = 1; | |
foo(); | |
} | |
goo(); | |
// ReferenceError: abc is not defined | |
*Note- foo method can't use abc variable as abc is not present in lexical scope chain. | |
For foo function lexical scope chain is like - foo scope -> global scope | |
---------------------------------------------------- | |
function goo() { | |
var abc = 1; | |
function foo() { | |
console.log(abc) | |
} | |
foo(); | |
} | |
goo(); | |
// 1 | |
*Note- For foo function lexical scope chain is like here - foo scope -> goo scope -> global scope |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment