Skip to content

Instantly share code, notes, and snippets.

@ssmereka
Created February 27, 2015 03:36
Show Gist options
  • Save ssmereka/1988d8be578e30849532 to your computer and use it in GitHub Desktop.
Save ssmereka/1988d8be578e30849532 to your computer and use it in GitHub Desktop.
Javascript Scope
var x = 5;
function one() {
console.log("one(): %s", x);
}
function two() {
console.log("two(): %s", x);
var x;
}
function three(cb) {
console.log("three(): %s", x);
var x = 4;
cb();
}
one(); // one(): 5
two(); // two(): undefined
three(one); // three(): undefined, one(): 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment