LearnFrenzy
Sign in Take a free test

Closures · Closures MCQ · Question 9

The module pattern Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links