IIFE stands for Immediately Invoked Function Expression. An anoymouns function that will be invoked soon after its declaration.

1
2
3
(() => {
console.log('I will be invoked right away!');
})(); // I will be invoked right away!

Though it looks weird or beautiful (to me ^_^), there are great benefits that come along with this IIFE approach.

Modularity

We can group our components or modules in a IIFE so that namespace conflicts reduced almost to none.

Scoping

We can declare our local functions and variables without worrying about polluting global scope or namespace conflicts.

1
2
3
4
5
(() => {
var personal = 'I am an Introvert!';
})();

console.log(personal); // ReferenceError: personal is not defined

Extras: