Skip to content

Instantly share code, notes, and snippets.

@jitendra19
Last active January 29, 2019 13:20
Show Gist options
  • Save jitendra19/831ab63dc78d0b660a1b7692b4e54931 to your computer and use it in GitHub Desktop.
Save jitendra19/831ab63dc78d0b660a1b7692b4e54931 to your computer and use it in GitHub Desktop.
JS questions
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