An immediately invoked function expression (IIFE) is a function expression that runs as soon as it is defined. Its function scope can hide internal variables while exposing only selected functionality. section 2.4
Used with closures, an IIFE can form the private boundary of a module: internal methods and data stay inaccessible, while exported methods provide the outside interface. This reduces globally shared data and references. section 2.4
A module boundary
A global MyModule object is passed into a function expression that executes when the script loads. Private variables such as _myPrivateVar remain local to the wrapping function, while exported methods use a closure to access the module’s internal state. section 2.4
An IIFE supports:
- Encapsulating internal variables and methods. section 2.4
- Exposing a deliberately limited set of functionality. section 2.4
- Packaging functional code inside well-encapsulated modules. section 2.4


