Consider this code:
let obj1 = {foo : 'bar'}
let obj2 = obj1
obj2.foo = 'asd'
console.log(obj1) // { foo: "asd" }
obj2 = null
console.log(obj1) // expected null, instead got { foo: "asd" }
If I understand right, when it comes to objects, by let obj2 = obj1 javascript does not actually create a new object, but references the same place in memory, hence the result of first log.
But, if obj2 is set to null, it actually leaves original object intact. How is this possible? I mean, I would expect either to be able to modify obj1 via obj2, or not. What causes this apparently selective behaviour? Thanks!