Immediately Invoked Function Expression (IIFE)

JS
S
JavaScript

IIFE - Design pattern which is also known as Self-Executing Anonymous Function which allows us to run functions whiteout polluting global namespace.

1// Example 1
2(function () { 
3    const type = 'Telemetry';
4})();
5
6// Example 2
7const result = (function () { 
8    const type = 'Telemetry';
9    return type; 
10})(); 
11// Immediately creates the output: 
12type; // "Telemetry"

Created on 7/3/2018