I have the following JS code:
let a = {
a1: 1,
a2: 1,
a3: 1
}
let b = a
b.a3 = 2
console.log(a) // { a1: 1, a2: 1, a3: 2 }
let d = a.a3
d = 3
console.log(a) // { a1: 1, a2: 1, a3: 2 }
With the first console.log
, I've set b
to a
, changed a property on b
, and seen that it is reflected in a
.
With the second console.log
, I've set d
to a property a3
of a
, changed d
, and seen that it is not reflected in a
.
Why the difference?