Immediately-Invoked Function Expression
Last updated 2 years ago
Was this helpful?
⟩ ⟩ ⟩ ⟩ IIFE
immediately-invoked function expression
a closure (or IIFE) can be used to create a scope to hide variables/functions.
break/continue won't operate across an IIFE function boundary to control an outer loop/block.
📗
if the code you need to wrap a scope around has return, this, break, or continue in it, don't use a function/IIFE(which has its own function boundary), use a block instead❗️
async IIFE
memoize by closure
// ⭐️ IIFE (function(){ // ... })(); // ⭐️ more compact form !function(){ // ... }(); // ⭐️ arrow function as IIFE (() => { // ... })();
arrow function can be used as IIFE.
IIFE is a function expression.
Node.js automatically wraps the code of a JS file in a self IIFE.
module pattern was implemented using IIFE.
JavaScriptTricks ⟩