On Thu, 07 May 2015 12:27:55 -0300, Joao Rodrigues wrote:
>
> An Immediately-Invoked Function Expression (IIFE) is usually written as:
> (function() { /* etc. */ })();
>
> Or:
>
> (function() { /* etc. */ }()); // Douglas Crockford's preference.
>
> But we can use unary operators instead of the wrapping parentheses too,
> if we don't care about the return value of the IIFE:
>
> +function() { /*...*/ }();
> !function() { /*...*/ }();
> -function() { /*...*/ }();
> ~function() { /*...*/ }();
>
> Even the void operator can be used:
> void function () { /*...*/ }();
With unary operators, it will make the JavaScript engine evaluate the
function return value using that operator. In theory, this will add more
processing time although it's very tiny.
With (), e.g. (function(){})(), there's no additional processing time.
But what about when using void? e.g. void function(){}()
If I understand it correctly, the function return value won't be evaluated,
but it does add additional code which replace the final expression with
undefined.