Skip to main content

Command Palette

Search for a command to run...

Deep Copy vs Shallow Copy

Published
•1 min read•View as Markdown

Shallow Copy:

A shallow copy creates a new object, but the properties of that object still refer to the same memory locations as the original object's properties. This is what happened in your array example

Deep Copy:

A deep copy creates a new object, and it also creates copies of all the properties within that object, including any nested objects or arrays. The new object and its properties are completely independent of the original object.

More from this blog

JavaScript fundamentals

8 posts