Question 9
Back to Exercise
What makes the module pattern const store = (function () { let items = []; return { add, list }; })(); work?
- A IIFEs create global variables
- B items is copied into each method
- C The returned methods close over items, which lives in the IIFE's scope Correct
- D The return statement freezes the object
Correct Answer: Option C
The IIFE runs once, creating a private scope; the public methods keep that scope alive.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!