#1 most askedVery commonMediumScope & closures
What is a closure?
🏢 Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.Explain what a closure is, and give a practical example of when you'd use one.
🔮 Predict the output
function makeCounter() {
let count = 0;
return () => ++count;
}
const a = makeCounter();
const b = makeCounter();
a();
a();
console.log(a(), b());
🎤 Answer it out loud, then check yourself
Say your answer as if the interviewer is listening (30–90 seconds). Then reveal what a strong answer covers and tick what you said.
Answer out loud first, then compare.
Want to rehearse it?Answer this to the AI interviewer and get a verdict →