Hint
IIFE + closure = module pattern for private state. The gold standard before ES modules.
const counter = (() => {
let _count = 0;
return {
increment() { return ++_count; },
reset() { _count = 0; },
get value() { return _count; }
};
})();
counter.increment();
counter.increment();
console.log(counter.value);
console.log(counter._count);
counter.reset();
console.log(counter.value);2 undefined 0
Explanation: _count is private inside the IIFE closure. The returned object can access it via closure, but external code cannot. counter._count is undefined.
Key Insight: IIFE + closure = module pattern for private state. The gold standard before ES modules.