Saturday, July 9, 2016

What are Immediately-Invoked Function Expression ?

IIFE for short, This is the self-invoking anonymous function. It executes immediately after it’s created.


Defining IIFE
Syntax : (function(){...})()

The first pair of parentheses (function(){...})() turns the code within into an expression,
and the second pair of parentheses (function(){...})() calls the function that results from that evaluated expression.

This pattern is often used when trying to avoid polluting the global namespace,
because all the variables used inside the IIFE are not visible outside its scope.

Passing parameter to IIFE
Syntax : (function(obj){...})(object);

Here the  (function(obj){...})(object) is passed as a parameter and will be accessible within the function as (function(obj){...})(object).

Related Posts Plugin for WordPress, Blogger...

Receive all updates via Facebook. Just Click the Like Button Below

You can also receive Free Email Updates: