This is becoming more common in a lot of code on the internet: something called immediately invoked function expression
The bit I don't understand it why people do that instead of just
It is actually 2 lines less. Also why do so many coders use inline variable assignments to function expressions. Why not just declare the function first and then call it like in any other language. Instead of
we get
It is actually more difficult to read because you cannot see the flow so easily as it is obscured by the function body (which can be pretty big).
What is the reasoning behind IIFE other than making code difficult to read, decipher and maintain?
Code:
// some code
(function(){
//do some work
})();
// more code
Code:
// some code
// do some work
// more code
Code:
// function decl
// some code
x = decl(...)
// more code
Code:
// some code
x = (function (...) {
// function body
} (...)
// more code
What is the reasoning behind IIFE other than making code difficult to read, decipher and maintain?