Skip to content

Instantly share code, notes, and snippets.

@kangax
Created September 2, 2009 01:51
Show Gist options
  • Save kangax/179491 to your computer and use it in GitHub Desktop.
Save kangax/179491 to your computer and use it in GitHub Desktop.
// first alert(1), then alert(2)
var foo = 1;
alert(1);
var bar = (function(){ alert(2); })();
// first alert(2), then alert(1)
var foo=1,bar=(function(){alert(2);})();alert(1);
/*
and if we preserve execution of expressions, then there doesn't seem to be any benefit in var hoisting
*/
var foo,bar;foo=1;alert(1);bar=(function(){alert(2);})();
// compare with a *shorter* original version:
var foo=1;alert(1);var bar=(function(){alert(2);})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment