Free webinar! How to Make Generative AI Work for You
Get my free ticket+ 5
IIFE stands for an immediately invoked function expression. A function that calls itself : Start with a regular function like
function selfCall () {
// code goes here
}
then you wrap the function in ( ) like this:
(function selfCall () {
})
And finally you call it with ();
So the completed IIFE will look like this:
(function selfCall () {
// code goes here
})();
+ 3
Nazim Sumra
Immediately invoked function expression (IIFE)
An immediately invoked function expression is a JavaScript programming language idiom which produces a lexical scope using JavaScript's function scoping.
+ 3
Nazim Sumra
JavaScript | Immediately Invoked Function Expressions (IIFE)
Functions are one of the building blocks of any programming language and JavaScript has taken the Functions to a whole new level. Functions are said to be a collection of statements to be executed in a proper sequence in a particular context. Now JavaScript provides a variety of methods to define and execute Functions, there are named functions, anonymous functions and then there are Functions that are executed as soon as they are mounted, these functions are known as Immediately Invoked Function Expressions or IIFEs. Let us dive deeper to know more about IIFEs.
Syntax: IIFEs follows a particular syntax as shown below.
(function (){
// Function Logic Here.
})();
+ 3
Nazim Sumra
Why the name Immediately Invoked Function Expressions?
Immediately Invoked: This part is easy to explain and demonstrate. This type of function is called immediately invoked as these functions are executed as soon as they are mounted to the stack, it requires no explicit call to invoke the function. If we look at the syntax itself we have two pairs of closed parentheses, the first one contains the logic to be executed and the second one is generally what we include when we invoke a function, the second parenthesis is responsible to tell the compiler that the function expression has to be executed immediately.
If you want to know about that with example, you can visit this website(
https://www.geeksforgeeks.org/javascript-immediately-invoked-function-expressions-iife/)😇😇