When you do
let a = {
name:'Pete',
};
let b = a;
let a = { name:'Pete'} means that create allocate some memory and store that object {name: 'Pete'} in that. And that memory location can be accessed using a variable named a
let b = a, since a is an object doing b = a points the variable b to the same memory location.
So, now we have two variables pointing to the same memory location. Making changes on the properties using any variable will be reflected when we try to access the data using any of the other variables. That's the reason why when you do a.name='Cindy'; or adding a new prop a.age=20; will be seen when we try to access b as well.
___________________
| |
a -----> | Memory Location 1 | <------ b
| { name: 'Pete' } |
|___________________|
Coming to doing a={};, meaning you are asking to allocate a new memory. So, now a and b points to different memory locations while b pointing to the old memory location. Hence, we'll still be able to see the value as {name: "Cindy", age: 20}
___________________
| |
a -----> | Memory Location 2 |
| {} |
|___________________|
_____________________________
| |
b -----> | Memory Location 1 |
| { name: 'Cindy', age: 20 } |
|_____________________________|