This is an instantly called function - as soon as you declare it, it calls the call.
The syntax () in Javascript means “call this function with any arguments between ( and ) . Since there is nothing between the brackets in your example, the arguments to the function are not passed; but if you need to specify arguments, you can do something like this:
(function foo(arg1, arg2) { alert(arg1 + " " + arg2); })(3, 5);
which will immediately call foo() and go into 3 and 5 as two arguments.
source share