An explanation of what is happening and why ...
In Javascript, you have function statements and function expressions . Both are similar, but not accurate.
Function operator
function myTest() {return true;}
Function Expressions
var f = function() {return true;} alert(f());
Updated due to comments
I prefer the first form because it allows me to use the block matching tools in my editor, and the f1 form is sometimes preferred by the useful JSLint and JSHint programs .
All create a function expression and then call it immediately. In this case, the partners do not need the Javascript compiler, but they provide very useful advice to the reader that this is not a normal purpose.
On the other hand, you have to tell the JS engine something that you have a function expression instead of a function operator. The = sign above works, but when there is no destination, you need to start with some kind of operator, be it (+!
!function(x, y) {alert(x, y)}(1, 2);
The lead statement makes this expression. () in the above examples also leads to its expression.
source share