Difference between shallow copy and deep copy

victoromondi1997 profile image VICTOR OMONDI ・1 min read

Shallow copy

Shallow Copy points to the same location in memory as 'Source' does. Which essentially means any changes made to the copied item, it will modify the source item as well. ❌

Deep copy

In deep copy it first creates a new object and then recursively populates it with copies of the child objects found in the original. In case of deep copy, a copy of object is copied in other object. It means that any changes made to a copy of object do not reflect in the original object.✔️

So whenver we do obj1 = obj, that's a shallow copy. [in Python and Javascript]


Editor guide