Don't forget about differences between shallow and deep copies...
const obj = { first: { second: 1 } } const copy = Object.assign({}, obj) copy.first.second = 2 console.log(obj.first.second) // -> 2 const copy2 = { ...obj } copy2.first.second = 3 console.log(obj.first.second) // -> 3
Both mentioned methods create only shallow copy of object.
Very true! I didn't want to get to deep into that as it may add confusion, but it's a good thing to look into next for sure!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Don't forget about differences between shallow and deep copies...
Both mentioned methods create only shallow copy of object.
Very true! I didn't want to get to deep into that as it may add confusion, but it's a good thing to look into next for sure!