Skip to content

Instantly share code, notes, and snippets.

@joshma
Created March 4, 2013 19:20
Show Gist options
  • Save joshma/5084679 to your computer and use it in GitHub Desktop.
Save joshma/5084679 to your computer and use it in GitHub Desktop.
Variable declarations in JS
var a = 0;
(function() {
var f = function() {
console.log(a);
};
f();
})(); // 0
var b = 0;
(function() {
var f = function() {
console.log(b);
};
f();
var b = 5;
f();
})(); // undefined, 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment