liveBook · Manning

Immediately invoked function expression

An immediately invoked function expression is a JavaScript function expression that is defined and executed immediately within the same syntactic construct, often creating an isolated scope.

How 3 Manning books explain it

Secrets of the JavaScript Ninja, Second Edition

A function expression that is defined and invoked immediately in the same syntactic construct.

How it is used
Uses immediate invocation to run one-time work and give pre-ES6 modules a scope for hidden variables.
How deep it goes
Explains call-expression syntax, then works through scoped state, closures, and an object-based module interface.
Examples
Shows immediate-call syntax, a click-counting module, and a DOM dimension utility that hides temporary style settings.
What you can do after
Build it from scratch to run setup immediately while keeping state private and exposing selected functionality.

Read how Secrets of the JavaScript Ninja, Second Edition explains immediately invoked function expression →

Functional Programming in JavaScript

An immediately invoked function expression is a function expression that is executed as soon as it is defined, typically to create an isolated scope.

How it is used
Uses immediate execution to create module boundaries that hide implementation details and limit globally shared data.
How deep it goes
Explains function scope, closures, private variables, and exported methods, but defers detailed variations of module patterns.
Examples
Demonstrates a MyModule skeleton whose private variables support exported methods through a closure.
What you can do after
Apply it via JavaScript function expressions to encapsulate module state and expose selected functionality.

Read how Functional Programming in JavaScript explains immediately invoked function expression →

The Joy of JavaScript

A function expression that is defined and executed immediately, often to create a private scope and avoid leaking bindings.

How it is used
Provides encapsulated namespaces, legacy modularity, and immediate startup execution without requiring a module system.
How deep it goes
Explains function-scope encapsulation, namespace exposure, mixin context, and async invocation, while deferring detailed module internals.
Examples
Uses a Transaction namespace, a HasHash mixin, and dynamic-import initialization as concrete applications.
What you can do after
Build encapsulated namespaces and mixins, or start asynchronous initialization through an immediately invoked async function.

Read how The Joy of JavaScript explains immediately invoked function expression →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.