Copying objects in javasceript to manipulate is common best practice.
✅ When you copy javascript objects or arrays keep in mind that only the outer properties are actually copied while the nested properties inside them only get referenced.
javascript default copy mode is shallow copy, to save on memory. But in the same time introduce a weird behavior.
💥When you try to change a property of a shallow copied object the change will effect the original object, that causes nasty bugs that get you stuck on for hours.
Top comments (0)