Skip to content

Instantly share code, notes, and snippets.

@aryak007
Created March 28, 2018 11:29
Show Gist options
  • Save aryak007/a1a781c8ddb1787b44aa2c632e93e5a6 to your computer and use it in GitHub Desktop.
Save aryak007/a1a781c8ddb1787b44aa2c632e93e5a6 to your computer and use it in GitHub Desktop.
// Lexical scope means compile time scope
var foo = "bar";
function bar(){
var foo = "baz"; //This is called shadowing. It will be in the local scope.
function baz(foo){
foo = "bam"; // Gets assigned to the local foo again
bam = "yay";
}
baz(); // JS variatic functions.
}
bar();
console.log(foo); // bar
console.log(bam); //yay
baz(); // Undefined Reference error!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment