Remove IIFE/IIAF

Remove immediately-invoked function expressions (IIFEs) and immediately-invoked arrow functions (IIAFs) without parameters.

Remove IIFE/IIAF

Why is this refactoring helpful?

IIFEs are common in older JavaScript code (pre-ES6). Before ES6, there were only var variable declarations and function declarations. IIFEs were used to create closures that prevent var and function declarations from affecting the global scope and prevent conflicts between different scripts and libraries using the same variable names.

With ES6, using block-scoped variable declared with let and const is preferable, and together with arrow functions, most IIFEs can be removed. Removing IIFEs can often simplify the code and make it more readable.

What do I need to consider?

Removing IIFEs with hoisted var or function declarations can lead to those declarations bleeding into the global scope or conflicting with similarly named variables from the surrounding scope.

Configuration

Related Code Assists

Learn More

Available In