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. 😄
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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
andlet
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. 😄