DEV Community

Discussion on: Spread ... The Love In JavaScript ❣️

Collapse
 
nainarazz profile image
Naina Razafindrabiby

I think the 'Deep Copy Object' heading is a bit misleading because the spread operator cannot do deep copying of objects. For example, if you have an object with nested objects, the spread operator will not be able to deeply copy the nested object.

const person1 = {
 name: 'person 1',
 address: {
        city: 'New York'
    }
}

const person2 = {
...person1
}

The address property in person 2 will still have a reference to the address property in person 1, meaning if the address in person 1 changes, address in person 2 will also change.

Collapse
 
radnerus profile image
Suren

Thanks for pointing out :) Updated the article (y)