Hint
All methods from a factory share one closure scope — one private variable, multiple public operations.
function createObj() {
let val = 0;
return {
inc() { val++; },
dec() { val--; },
reset() { val = 0; },
get() { return val; },
};
}
const obj = createObj();
obj.inc(); obj.inc(); obj.inc(); obj.dec();
console.log(obj.get());
obj.reset();
console.log(obj.get());2 0
Explanation: All four methods close over the same val variable. They share and mutate the same binding.
Key Insight: All methods from a factory share one closure scope — one private variable, multiple public operations.