Sep 6, 2018 · 1 min read
When you assign to another empty object, it is not “cleaning” the original object. You are just simply removing the reference to original object, create additional empty object and assign the original variable (in this case is t ) to point to new empty object instead.
If the original object is referred by some other variables, it still exists because JS garbage collector will only delete it when there is absolutely no reference to it. For example:
var t = {1: 'a', 2: 'b', 3: 'c'}
var aRef = t //aRef points to the same object with t//OR
var firstParam = t['1']t = {}
console.log(aRef) // still print out {1: 'a', 2: 'b', 3: 'c'}
console.log(t) // {}
console.log(firstParam) // still 'a'
It is not correct way to clean it especially when you don’t know how many time the original object or its properties are referred in the code. Hope it is clear 😃
