Skip to content

Instantly share code, notes, and snippets.

@disnet
Created September 5, 2012 18:28
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 disnet/3642049 to your computer and use it in GitHub Desktop.
Save disnet/3642049 to your computer and use it in GitHub Desktop.
JavaScript var hoisting

Here's the standard example:

var x = "bar";
(function() {
  console.log(x) // undefined
  var x = 42;
})()

But what happens when you have a parameter?

(function(x) {
  console.log(x) // "foo"
  var x = 42;
})("foo")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment