0Pricing
JavaScript Academy · Lesson

The Module Pattern (IIFE)

Encapsulate code with immediately invoked functions.

What the Module Pattern Solves

Before ES modules, the module pattern let you bundle related state and behavior while keeping internals private and exposing a clean public API. It is built on closures.

The IIFE

An IIFE (Immediately Invoked Function Expression) is a function that runs the moment it is defined. Wrapping in parentheses and calling it creates a private scope instantly.

const result = (function () {
  return 42;
})();
console.log(result); // 42

All lessons in this course

  1. How Closures Capture State
  2. Private Variables with Closures
  3. The Module Pattern (IIFE)
  4. Factory Functions
← Back to JavaScript Academy