• Tutorials Logic, IN
  • +91 8092939553
  • info@tutorialslogic.com

IIFE (Immediately Invoked Function Expression)

IIFE

An IIFE stands for Immediately Invoked Function Expression. IIFE is a design pattern as well as the JavaScript function that executes as soon as they are defined. IIFE are very useful in javascript as they don't pollute the global object. An IIFE is a simple way to isolate variables declarations, as it is a good way of protecting the scope of your function and the variables within it.

Creating an IIFE

										    
											(function() {
												console.log("Welcome to Tutorials Logic!");
											})();
											
										

An IIFE can also be defined with arrow functions like this:

										    
											(() => {
												console.log("Welcome to Tutorials Logic!");
											})();
											
										

An IIFE can also be defined using named regular functions (except arrow functions) like this:

										    
											(function myFunction() {
												console.log("Welcome to Tutorials Logic!");
											})();