Search code examples
javascriptself-invoking-function

Different between (function(){})() and (function(){}()) , self invoking anonymous function


Look at the placement of the parenthesis, is that any different?

( func )( )

(function(){

})();

and ( func( ) )

(function(){

}());

Solution

  • Technically the first defines an anonymous function, then calls it, the second defines an anonymous function which calls itself as it's defined. Realistically, they are identical.