A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-164.js
1functionsnapshot(x){
2return()=>x;
3}
4constfns=[snapshot(1),snapshot(2)];
5letx=99;
6console.log(fns[0](),fns[1]());
Scope
Answer & explanation
Console output
1 2
Why
Each call to snapshot binds its own parameter x and returns an arrow that captures that specific binding, freezing the value passed in. The later outer let x = 99 is a separate variable that the closures never reference, so they still return 1 and 2. Currying and factory functions rely on exactly this per-call capture to take independent snapshots.