← BYTES
JavaScript·Intermediate·Ref: 3.2.18
What is the (now largely superseded) module pattern using an Immediately Invoked Function Expression (IIFE) used for?
Have a question about this video? Mention reference 3.2.18 when you contact us.
a.Making code run faster by avoiding function calls entirely
b.Running code exactly once per page load, enforced by the browser
c.Automatically minifying the enclosed code
d.Creating a private scope for variables/functions, exposing only a deliberately chosen public interface, before ES6 modules existed
Before ES6's native `import`/`export`, wrapping code in `(function() { ...; return publicAPI; })()` was the standard way to get private, encapsulated state (via closures) while exposing only an intentional public interface, simulating what real module scoping now provides natively.
Find this on YouTube & Instagram
Every BYTES video is tagged with its reference number and topic — search any of these on YouTube or Instagram to find this one:
#BYTES#BYTES3218#JavaScript