Can you explain the reasoning behind the syntax for encapsulated anonymous functions in JavaScript? Why does this work: (function(){})(); but
(function(){})();
They can be used with parameters-arguments like
var x = 3; var y = 4; (function(a,b){alert(a + b)})(x,y)
would result as 7