Loading the explainer…
Follow a function and its captured variable after the outer call has returned.
This is why a returned function can remember state after its creator has finished.
Calling makeCounter creates a lexical environment and initializes its count binding to 0.
function makeCounter() {
let count = 0;
return () => ++count;
}
const counter = makeCounter();
console.log(counter(), counter());What does this print?