Technical

What is a closure in JavaScript?

Updated 10 October 2026 2 min read By LaunchCV.in

It shows depth in a core JavaScript concept.

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

  1. Define a closure
  2. Show a tiny counter example
  3. Explain why the variable persists
  4. 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.

Note: This is general information, not professional advice, and it cannot guarantee any job, admission, salary or result. Check official sources for current rules and dates.