11 KiB
| title | chunk | source | category | tags | date_saved | instance |
|---|---|---|---|---|---|---|
| IIFE - Glossary | MDN | 1/3 | https://developer.mozilla.org/en-US/docs/Glossary/IIFE | reference | web, html, css, javascript, documentation | 2026-05-05T05:34:32.032675+00:00 | kb-cron |
MDN HTML HTML: Markup language
HTML reference
HTML guides
Markup languages
CSS reference
CSS guides
Layout cookbook
JavaScriptJS JavaScript: Scripting language
JS reference
JS guides
Web APIs Web APIs: Programming interfaces
Web API reference
Web API guides
- Using the Web animation API
- Using the Fetch API
- Working with the History API
- Using the Web speech API
- Using web workers
Technologies
Topics
Learn Learn web development
Frontend developer course
- Getting started modules
- Core modules
- MDN Curriculum
- Check out the video course from Scrimba, our partner
Learn HTML
Learn CSS
Learn JavaScript
Tools Discover our tools
About Get to know MDN better
IIFE
An IIFE (Immediately Invoked Function Expression) is an idiom in which a JavaScript function runs as soon as it is defined. It is also known as a self-executing anonymous function. The name IIFE is promoted by Ben Alman in his blog. It contains two major parts:
- A function expression. This usually needs to be enclosed in parentheses in order to be parsed correctly.
- Immediately calling the function expression. Arguments may be provided, though IIFEs without arguments are more common.
IIFEs are a common pattern used to execute arbitrarily many statements in their own scope (and possibly return a value), in a location that requires a single expression. They are similar to, but much more powerful than, the comma operator, which can only execute multiple expressions and, therefore, does not provide a way to use local variables or control flow statements. Use cases of IIFEs include:
- Avoiding polluting the global namespace by creating a new scope.
- Creating a new async context to use
awaitin a non-async context. - Computing values with complex logic, such as using multiple statements as a single expression.
For code examples, see the function expression and async function expression reference pages.
In this article
See also
- IIFE (Wikipedia)
- Comma operator
- Related glossary terms: