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