IIFEs

An immediately invoked function execution is a function that is defined and then immediately executed.

A common reason for writing an IIFE is to create a new scope with an independent set of variables. In the example below, the variable i is incremented during each iteration of the for loop.

Loading TypeScript...

Async IIFE

TypeScript may restrict your ability to use await on a global function invocation. To invoke one or more asynchronous functions with await, use an async IIFE.

Loading TypeScript...

Was this page helpful?