[[Snippets]] # [[JavaScript IIFE]] > [!INFO] A [[JavaScript]] [[Function]] that runs as soon as it is defined. It is a [[Design Pattern]] which is also known as a [[Immediately Invoked Function Expression|Self-Executing Anonymous Function]] and contains two major parts: > 1. An [[Anonymous Function]] with [[Lexical Scope]] enclosed within the [[Grouping Operator]] `()`. This prevents accessing [[Variable|Variables]] within the [[Immediately Invoked Function Expression|IIFE]] [[Idiom]], as well as polluting the [[Global Scope]]. > 2. The [[Immediately Invoked Function Expression]] itself `()`, through which the [[JavaScript Engine]] will directly interpret the [[Function]]. ## Syntax ```javascript // Via Function Expression (function () { let variableX; }) (); // Via Arrow Function (() => { let variableY; })(); // Via Asynchronous Function (async () => { … })(); ``` # Links - One of many [[JavaScript]] [[Function|Functions]]