Question 5 of 10Pro Only

How can closures cause memory leaks in JavaScript? Give examples and explain how to avoid them.

Sample answer preview

Closures capture references to variables from their outer scope. This powerful feature can accidentally prevent the garbage collector from freeing memory. Closures work by retaining access to outer variables.

closurememory leakgarbage collectionremoveEventListenerclearIntervalWeakMap

Unlock the full answer

Get the complete model answer, key points, common pitfalls, and access to 9+ more Frontend Developer interview questions.

Upgrade to Pro

Starting at $19/month • Cancel anytime