Module Pattern
Module Pattern — The module pattern encapsulates private variables and methods using closures, exposing only a public API. Before ES6 modules, the module pattern was the primary way to create private state in JavaScript. It uses an IIFE that returns an object with only the public methods. ES6 native modules (`import`/`export`) have largely replaced this pattern for file-level code organization, but the module pattern remains useful for in-module encapsulation. This term relates to the Object category of the reference. You will meet module pattern in practice when working with APIs such as Object.keys(), Object.values(), Object.entries(), Object.assign(). Related terms: Closure, Hoisting, Event Loop, Prototype Chain, Temporal Dead Zone (TDZ), IIFE (Immediately Invoked Function Expression). Understanding module pattern makes the rest of the JavaScript documentation noticeably easier to follow, because the concept recurs across methods, guides, and error messages. Look up more definitions in the JavaScript glossary.