Why interviewers ask this
It shows depth in a core JavaScript concept.
How to approach it
Define it simply and give a short counter example.
Example answer
A closure is a function that remembers variables from the scope where it was created, even after that scope has finished. For example, a function that returns another function that increments a private counter.
What a weak answer sounds like
A closure is a function inside a function.
It is vague, has no example and gives the interviewer nothing to remember.
A simple structure for your answer
- Define a closure
- Show a tiny counter example
- Explain why the variable persists
- Name a real use, such as private state or callbacks
Freshers and experienced candidates
Freshers need a clear example; experienced candidates should mention memory use and loop pitfalls.
Common mistake
Confusing closures with callbacks.
Self-check before the interview
Can you write the counter example from memory without notes?
Follow-up questions to expect
- Where are closures useful in real code?
- What is the difference between var, let and const?
- What is a common closure bug in loops?
How to practise
Write a small counter function using a closure and explain why the variable persists.
Use this as a pattern, not a script. Answer in your own words with your own examples.