Maya Shavin
Sep 6, 2018 · 1 min read

Master Result

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 😃

    Maya Shavin

    Written by

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade