JavaScript · Middle · Question 13 of 75
What was an IIFE (function () { ... })() used for in the past?
- ✓Correct answer: To create an isolated scope and avoid polluting the global one
- 2To speed up the function through early compilation
- 3To run the function asynchronously after the page loads
Explanation
Before let/const and modules, a function was the only way to hide variables. An IIFE created a private scope (the "module" pattern). Today ES modules and blocks solve this, and IIFEs are sometimes used for top-level async code.