PRACTICE / UNDERSTAND / REPEAT
JavaScript: Scope & closures
Practice scope & closures with self-contained questions. Check your answer, then use the explanation to understand the reasoning.
20 questionsAnswers explainedFree · no login
Question 1 of 20
What does the final call print?
function counter() {
let count = 1;
return () => ++count;
}
const next = counter();
next();
console.log(next());
Answer & explanation
Answer: 3
The returned function retains access to the same count binding. Each call increments it.