Skip to content

Instantly share code, notes, and snippets.

@eliperelman
Created July 6, 2011 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliperelman/1066473 to your computer and use it in GitHub Desktop.
Save eliperelman/1066473 to your computer and use it in GitHub Desktop.
Hoisting
// Antipattern:
var x = 10;
var y = function () {
console.log(x); // logs undefined
var x = 20;
return x + 10;
};
// Good pattern:
var x = 10;
var y = function() {
var x = 20;
console.log(window.x);
return x + 10;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment