Sunday, July 3, 2022

IIFE(Immediately Invoked Function Expression) & Arrow function

 Immediately Invoked Function Expression(IIFE) is an anonymous function which gets invoked immediately. It is anonymous because it does not have a function name. The nature of this kind of function are self invoking. 



Here we can see that we have declared a function without a name. Inside a block function it has defined a variable with number 30 locally which is not defined outside the block. Therefore, we can see lexical behavior here also.

Below are some related questions to IIFE.

1.What is Name Collision?

2.Normal Function vs IIFE?

  • At the time we create normal function we can have name collision but incase of IIFE we don't face this problem.

3.What is the use of IIFE?

  • To not have a name collision is the use of IIFE. 


Arrow Function:
Arrow function allows us to shorten the syntax of function as compared to normal function.






No comments:

Post a Comment

IIFE(Immediately Invoked Function Expression) & Arrow function

 Immediately Invoked Function Expression(IIFE) is an anonymous function which gets invoked immediately. It is anonymous because it does not ...