IIFE Pattern in JavaScript
Level 3114 keystrokes
IIFE (Immediately Invoked Function Expression) runs immediately and creates a private scope.
JavaScript code
// IIFE - function that runs immediately when defined// Wrapped in parentheses and followed by () to call it1const result = (() => { // Variables inside are private to this scope2 const a = 5;3 const b = 10; // Return value is assigned to result4 return a + b;5})();// result is 156console.log(result);// a is not defined outside the IIFE - prints "undefined"7console.log(typeof a);Output
15 undefined
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this JavaScript code and how often they appear.
;× 6(× 5)× 5=× 4.× 2{× 1}× 1+× 1>× 1