From the developer.mozilla.org/ page on “Deep copy”:
The copy of an object whose properties all have primitive values fits the definition of both a deep copy and a shallow copy.
I’m not sure I understand this quote.
I know that copies of primitive values are deep copies:
x = 'hello';
y = x;
y = 'world';
console.log(x)
console.log(y)
But as regards objects, that’s not true:
x = { k: 'v' }
y = x;
y.k = 'w';
console.log(x)
console.log(y)
In the latter snippet, doesn’t x
match the description of
an object whose properties all have primitive values
given that it has just one property to which a string value 'v'
is associated?
That’s enough to show the difference between shallow and deep copy, so what is the quote above referring to?