DEV Community

Discussion on: What is IIFE in JavaScript?

Collapse
 
adnanrahic profile image
Adnan Rahić

It all boils down to scopes. JavaScript is weird, well actually ES5 is weird. Back then with the var keyword, variables we're limited by function scope. Meaning, only functions could create scopes, unlike normal languages that have block scopes (i.e. a for loop creates a separate scope).

Nowadays with const and let block scopes are added in ES6 and above. Hence, making IIFEs less prominent as of late.

To get back to the question. Every normal language that has block scopes has this behavior. 😄