Learn JavaScript
Immediately Invoked Function Expression
22.1
Lesson

IIFE

Sometimes, we want to execute a function as soon as it is defined. For these purposes, we can use IIFE which is an Immediately Invoked Function Expression.

The variables declared inside cannot be accessed from outside the IIFE.

You can also execute the function expression as shown in the example below. The location of the executing parentheses does not change the output.