JavaScript IIFE | Immediately Invoked Function Expression Example code

JavaScript IIFE stands for an immediately invoked function expression. It defined as a function expression and executed immediately after creation.

It is a design pattern which is also known as a Self-Executing Anonymous Function

Syntax

Defining an immediately invoked function expression:

Immediately invoked function expression (IIFE) Example

Let’s see the HTML example of the function becomes a function expression that is immediately executed.

Output:

JavaScript IIFE Immediately Invoked Function Expression

Note: The variable within the function expression can not be accessed from outside it.

Do comment if you have any doubts and suggestion on this topic.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.