A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-4.js
1functionmake(){letc=0;return()=>++c;}
2consta=make(),b=make();
3console.log(a(),a(),b());
Scope
Answer & explanation
Console output
1 2 1
Why
Each invocation of make() creates a fresh lexical environment with its own c, and the returned arrow closes over that specific variable. a and b therefore have independent counters: a() yields 1 then 2 on its own c, while b() starts fresh and yields 1. Closures capturing per-call state are the foundation of factory functions and private variables.