Skip to content

Instantly share code, notes, and snippets.

@dperini
Forked from kangax/gist:179491
Created September 2, 2009 03:36
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 dperini/179535 to your computer and use it in GitHub Desktop.
Save dperini/179535 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);})();
// these are both shorter than the above same results
var foo=1,x=alert(1),bar=(function(){alert(2);})();
var foo=1,bar=(function(){alert(2);})(alert(1));
// still short like the above, more unreadbale
var foo=1,a=alert,bar=(function(){a(2);})(a(1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment