Posted in Interesting, Programming, Web Tech

IIFE : Immediately Invoked Function Expression

What is IIFE?

As the name says, IIFE, Immediately Invoked Function Expression is a function which is immediately invoked as soon as it is defined in javascript programming. It is a very popular way of handling javascript programs where the interpret runs it only once.

Different syntax:

  1. ( function( ){ //statements })( );
  2. ( function( ){ //statements }( ));
  3. ( ( )=>{ //statements })( );

It has two parts: One is the function enclosed within () group operator, helps in accessing variables within function and second part which directly creates the immediately invoked function expression () which the javascript engine interprets. This whole concept of design pattern is called as Self Executing Anonymous Function.

As the function name is not used, they are called as anonymous function.

When is IIFE important?

As IIFE is executed once it is defined and interpreted once by javascript engine.

It maintains encapsulation and avoids polluting of variables which are not required for global access.

The code which does not have reusability can also be a part of IIFE. Hence this function is also an anonymous function.

Author:

I'm really glad that you stopped by. If you like blog posts feel free to follow, like, share, comment etc. If you have any suggestions or would like to learn or understand any topic, you can always write to me. I believe that, reading and writing heals and fuels the soul 🙂 Keep visiting and happy reading 🙂Twitter handle @_ViniTweet_ Cheers to You! ♥

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s