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.
Common mistake
Confusing closures with callbacks.
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.