I'm learning Javascript, based on my knowledge that the reference type like object below is created in the heap, and point to a new piece of memory in the stack. But what happened when I've tried to declare an object like this:
let object = { id: 1223, title: 'test' };
and when I reassigned it:
object = { newId: object.id, newTitle: object.title };
I got:
object = { newId: 1223, newTitle: 'test' };
I'm so curious as to why this is possible, Has the property name gone when I reassigned the object? and How it works behind the screen?
Please give me some explanations, keywords, or documents.
Many thanks.
P/s. Something I forgot is that the =
operator's associativity happened from right to left, so the object at this point was not mutated until the execution met the =
. Maybe it is the answer for my question somehow.