Why Immediately-Invoked Function Expression (IIFE) are different from Self-Executing Anonymus Functions?

StackOverflow https://stackoverflow.com/questions/12508359

  •  03-07-2021
  •  | 
  •  

Question

It is clear that in EcmaScript, functions when invoked create a new execution context. All variables and functions defined within a function may only be accessed inside that function scope. But when we use closures variables and functions may be accessed outside that context. IIFE is a function expression that gets invoked immediately. It is simple.

But why are IIFE different from Self-Executing Anonymus Functions, it is not completely clear to me!?

Was it helpful?

Solution

They are the same, it was renamed to IIFE because an IIFE is not necessarily anonymous, and they do not execute themselves.

consider the following:

(function bleh() {
    alert('I am not anonymous, i have a name!');
})(); //<-- invoked like any other function
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top