Skip to content
Onsite

Output: makeCounter called twice, each counter incremented separately

EasyP2Output

What does this code print?

1function makeCounter() {
2 let n = 0;
3 return () => ++n;
4}
5const a = makeCounter();
6const b = makeCounter();
7console.log(a(), a());
8console.log(b());
9console.log(a());
Saved automatically

One line per console.log. Arrays as [1, 2, 3], objects as { a: 1 }, an uncaught error as Uncaught TypeError: message (Chrome and Node wording).

Hints

Saved automatically