Point 3.8 looks unclear regarding spread operator. [javascript] - TagMerge

Point 3.8 looks unclear regarding spread operator. [javascript]

Yatin-kathuriaAsked 6 months ago

Point 3.8 looks unclear regarding spread operator.

refer the object spread operator over Object.assign to shallow-copy objects. Use the object rest operator to get a new object with certain properties omitted.

actually

The spread operator makes deep copies of data if the data is not nested. When you have nested data in an array or object the spread operator will create a deep copy of the top most data and a shallow copy of the nested data.

References

Medium Stackoverflow

Source: link

ljharbAnswered 6 months ago

What part is unclear?

The spread operator does not make a deep copy of anything; medium and SO are not authoritative references of anything. Nothing in JS makes a deep copy of anything.

Yatin-kathuriaAnswered 6 months ago

I hope MDN is a good source to verify

This is from copy an array section on mdn

Note: Spread syntax effectively goes one level deep while copying an array. Therefore, it may be unsuitable for copying multidimensional arrays, as the following example shows. (The same is true with Object.assign() and spread syntax.)

ljharbAnswered 6 months ago

Yes; "one level deep" is "shallow" which is "not deep".

Recent Issues

    Programming Languages