KASA
Back to interview Q&A
Frontend DeveloperJavaScript Closuresbeginner

What is a closure in JavaScript?

This question tests whether a candidate understands lexical scope and how functions remember variables.

0
Asked by KASA community7 Jul 20262 views
KASA answer
A closure in JavaScript means an inner function has access to variables defined in its outer function, even after the outer function has returned. This happens because functions carry their lexical environment with them. For example, a function that returns another function can keep a private counter variable. Every time the returned function runs, it can still access and update that counter. Closures are used in callbacks, event handlers, function factories, private state, and many React patterns.
Cover these points
  • A function remembers its lexical scope.
  • The outer function may finish, but variables can still be accessed.
  • Closures help create private state.
  • Common in callbacks, event handlers, and function factories.

Community answers

0 approved answers

Add answer

No approved community answers yet

Add a clear answer with examples. It will appear after moderation.

Question discussion

Comments and follow-ups

No approved comments yet. Add useful context or ask a follow-up.

Login to join the discussion

Write an answer

Add a practical answer with examples, edge cases, project experience, and points a fresher can speak in an interview.

Login required. Your answer will be connected to your account and sent for moderation.

Keep practising

Related interview questions

Browse all