Skip to content

Instantly share code, notes, and snippets.

@hackjutsu
Last active October 15, 2016 00:28
Show Gist options
  • Select an option

  • Save hackjutsu/6c943f91e08316071bc667d72b74b94f to your computer and use it in GitHub Desktop.

Select an option

Save hackjutsu/6c943f91e08316071bc667d72b74b94f to your computer and use it in GitHub Desktop.
Example explaining the lexical scope in JS
var a = 10;
function add() {
var b = 20;
return a + b; // a is bound to the global a when the function object add() is created.
}
// call add() -> 30
(function() {
var a = 20;
var result = add();
console.log("result: " + result);
}())
// result: 30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment