Well in the first case you are using ( )
to wrap the object you want to execute with the next set of ()
, and in the next case you are using operator that takes one argument (negation operator !) and you are making it implicitly wrap its argument (funcion) with ( )
so you actually get !(function () { })()
, execute the function, and negate the result it returns. This can also work with -, +, ~
in the same principle since all those operators take one argument.
!function () { /* presumably the same magic happens */ }()
-function () { /* presumably the same magic happens */ }()
+function () { /* presumably the same magic happens */ }()
~function () { /* presumably the same magic happens */ }()
Why would you want to do this? I guess it is a personal preference or if you have big .JS and want to save 1 char per anonymous function call... :D