Remove immediately-invoked function expressions (IIFEs) and immediately-invoked arrow functions (IIAFs) without parameters.
Why is this refactoring helpful?
Before ES6, there were only
var variable declarations and function declarations.
IIFEs were used to create closures that prevent
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
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.