there are two (common) ways to implement an IIFE in Javascript.
// Way 1
(function(){
/* My IIFE Body*/
})()
//Way 2
!function(){
/* My IIFE Body*/
}()
I want to know if there is a good reason that one would use the second one.
I only see reasons to not use the second one. For example if you want your IIFE to return something you cannot assign it to a variable like this:
var x =
(function()
{ return 5; })(); // x will be 5
var y =
!function()
{ return 5; }(); // y will be true
since it will be cast to boolean. Whenever I want to access an object from a Way-2-IIFE I use a closure like in this fiddle.
There is also no performance boost for the second variant as you can see here.
So are there any good reasons to use method two? If so, can you give me an example ?