I see that Immediately-Invoked Function Expression, or IIFE for short is executed immediately after it’s created.
The first pair of parentheses (function(){...}) turns the code within (often a function) into an expression, and the second pair of parentheses (function(){...})() calls the function that results from that evaluated expression.
This pattern is often used when trying to avoid polluting the global namespace. Is this the only reason? The example I see such as
(function(){
// all your code here
var foo = function() {};
window.onload = foo;
// ...
})();
// foo is unreachable here (it’s undefined)
don't show a function name that can then be called. If that is the reason - not to create a function, but to execute it immediately then that seems like more than just the namespace issue ?