JavaScript · Middle · Question 13 of 75

What was an IIFE (function () { ... })() used for in the past?

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.

Further reading

Problem with a question

JavaScript · Middle · question 13

Test yourself

Take the JavaScript · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz