IIFE in Javascript

 IIFE in Javascript

In this article we are goanna to see about IIFE in Javascript and where we use these. which is most important when you are going to start your career in JavaScript. Please ready and enjoy this article if you want to give any feedback about your experience, we welcome.



Immediately Invoked Function Expression (IIFE) is one of the most popular design patterns in JavaScript. It pronounces like IIFY.

An IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined.

Important points:

1. IIFE follow their own scope like any other function/variable in JavaScript.

2. IIFEs have there own scope i.e. the variables you declare in the Function Expression will not 

     be available outside the function.

3. Similarly to other function IIFEs can also be named or anonymous, but even if an IIFE does 

     have a name it is impossible to refer/invoke it.

4. IIFEs can also have parameters.

Syantx:

(function() { function body })();

Ex:

//Normal function

function myfun( ){

document.write(“Hello world”);

};

//IIFE

(function( ) {document.write(“Hello world”);})();


Share:

0 comments

Please leave your comments...... Thanks