HomePremium · ₹1199
← All questions

How do closures work in JavaScript?

Easy
Was this asked in an interview?

Explain closures, give a real-life example, and solve closure-based output questions.

Answer

A closure is the combination of a function and the lexical scope in which it was created. The inner function retains access to the outer function's variables even after the outer function has returned.

Real-life uses: data privacy (private state), function factories, memoization, event handlers, and module patterns.

How do closures work in JavaScript? — JavaScript Interview Question | Mentoxis