Question PRG-JS-0065
HardWhat is the output of this program?
function counter() {
let n = 0;
return { inc: () => ++n, get: () => n };
}
const c1 = counter(), c2 = counter();
c1.inc(); c1.inc(); c2.inc();
console.log(c1.get(), c2.get());
- A.
2 2
- B.
2 1
- C.
Sign up free to see the answer and a step-by-step explanation.