5 exercises on JavaScript memory model vocabulary.
0 / 5 completed
1 / 5
In JavaScript, where are objects stored versus primitive values in local variables?
Heap vs stack: primitive values (number, boolean) are copied by value, while objects and arrays are allocated on the heap and variables hold a reference. Assigning an object copies the reference, not the data.
2 / 5
How does JavaScript reclaim unused memory?
Garbage collection: the engine periodically finds objects unreachable from roots (global scope, call stack) and frees them. Developers do not call free; instead they avoid keeping unwanted references alive.
3 / 5
What is a common cause of a memory leak in JavaScript?
Memory leak: because GC only frees unreachable objects, an accidentally retained reference (a detached DOM node held by a closure, an unbounded cache) keeps memory alive indefinitely, growing usage over time.
4 / 5
What does a closure capture in terms of memory?
Closure capture: a function retains access to variables from where it was defined. Those variables cannot be collected while the closure lives, which is powerful but can unintentionally retain large objects.
5 / 5
How does a WeakMap help avoid memory leaks?
WeakMap: unlike a regular Map, a WeakMap does not prevent its key objects from being collected. This lets you associate metadata with objects without keeping them alive, ideal for caches keyed by DOM nodes.