DEV Community

VICTOR OMONDI
VICTOR OMONDI

Posted on

2

Difference between shallow copy and deep copy

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]

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay