So, we know that value of variables that contain objects in javascript are passed by reference. for example:
let a = {name:'john'};
let b = a;
a.name = 'doe';
console.log(b.name)//prints out doe
but:
let a = {name:'john'};
let b = a;
a = {name: 'not john'}
console.log(b.name)//should printing not john, but instead keeps showing john
How this is possible ? Value of variable a are replaced with a new object with a different value. Object with a name property john are gone and variable b should refer to variable a with property value 'not john' but it keeps refering to an objects which doesn't exist !