DEV Community

Cover image for Immediately Invoked Function Expression
Antony Kimani
Antony Kimani

Posted on

3 1

Immediately Invoked Function Expression

I was struggling to understand IIFE's so I wrote about it. Hopefully this article helps you understand IIFE's in a Jiffy.

Immediately Invoked Functions are Functions that execute as soon as it is defined.

Here is an Example:

(function(){
    console.log('This is an Immediately Invoked Function');
})();
Enter fullscreen mode Exit fullscreen mode

It has two enclosing parenthesis , the First parenthesis makes the function an expression and the last parenthesis tells the JavaScript compiler to invoke or call the function Immediately.

The Expression evaluates itself to execute the function.

Is that it?

what are the uses of IIFE?

1. Avoid Calling Variables in the global scope and create closures

With IIFE being executed immediately it means variable names will not conflict.This is better in situations where we don't need to use the function again.

However, with the introduction of let and const variable keywords we can differentiate between global and block scope variables.

Hope this explained the concept in an easy , beginner-friendly manner.Cheers

Image of Wix Studio

2025: Your year to build apps that sell

Dive into hands-on resources and actionable strategies designed to help you build and sell apps on the Wix App Market.

Get started

Top comments (0)

Image of Bright Data

Maintain Seamless Data Collection – No more rotating IPs or server bans.

Avoid detection with our dynamic IP solutions. Perfect for continuous data scraping without interruptions.

Avoid Detection

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay