IIFE can be called in different ways.
It so happened that usually IIFE is wrapped in brackets; this is necessary in order to make the parser explicitly aware that there will be an expression, not a function declaration.
Otherwise, upon encountering function , the declaration will start parsing:
(function () { /* ... */ })(); (function () { /* ... */ }()); (() => { /* ... */ })(); // В стрелочных функциях скобки разрешены только снаружи
Although brackets are optional, these options also work:
!function () { /* ... */ }(); ~function () { /* ... */ }(); -function () { /* ... */ }(); +function () { /* ... */ }(); void function () { /* ... */ }();
If it is clear from the context that there should be an expression here, it is no longer necessary to clearly indicate:
var f = function () { /* ... */ }(); true && function () { /* ... */ }(); 0, function () { /* ... */ }();
Wiki