Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
A closure retains access to variables in its enclosing lexical scope, even after the outer function returns.
In function makeCounter() { let count = 0; return () => ++count; }, the returned function closes over count. Calling const next = makeCounter(); next(); next() returns 1 and then 2. It accesses the same binding rather than a fresh copy on every call. A second call to makeCounter creates a separate count binding for a separate counter.