Automatic Memory Cleanup
In JavaScript, you don't need to manually delete objects from memory. The engine does it for you.
Main Criterion: Reachability
An object remains in memory as long as it is " reachable " from a root (e.g., the global window variable).
let user = { name: "John" };
user = null; // The reference is lost. Now the object { name: "John" } is unreachable
// and will be removed by the garbage collector.
Note
The primary garbage collection algorithm is called ** " Mark-and-sweep " **. It periodically " walks " through the reference graph and sweeps away anything that isn't marked.