Closures JavaScript Interview Questions
7 curated closures interview questions for JavaScript — with short answers, detailed explanations, and interview tips. Ideal for Fresh through Tech Lead prep.
What is a closure in JavaScript?
How can closures create private state, and when is that useful?
Why does this print `3 3 3` instead of `0 1 2`, and how do you fix it? ```js for (var i = 0; i < 3; i++) { setTimeout(() => console.log(i), 0); } ```
How can closures cause memory retention problems?
Implement a simple `partial` or `multiplyBy` using closures. What interview signal does this show?
What is a stale closure, and how would you diagnose it in an async UI callback?
When designing a library API, when would you prefer closure-based factories over class instances with prototype methods?