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
Scope & closures · MCQQuestion link ↗

What does the final call print?

function counter() {
  let count = 1;
  return () => ++count;
}
const next = counter();
next();
console.log(next());
Choose one answer
Answer & explanation

Answer: 3

The returned function retains access to the same count binding. Each call increments it.