A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-95.js
1functioncounter(start){
2returnfunction(){returnstart++;};
3}
4constc=counter(10);
5console.log(c(),c(),c());
Scope
Answer & explanation
Console output
10 11 12
Why
The inner function closes over the parameter start, which persists across calls because the closure keeps its environment alive. The post-increment start++ returns the current value before adding one, so successive calls yield 10, 11, then 12. A parameter used as mutable closed-over state is the simplest possible stateful counter.