<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/shallow-vs-deep-copy-in-javascript-rw6zwkasn" -->

---
title: Shallow vs Deep Copy in JavaScript | daily.dev
description: A quick explainer distinguishes shallow copies (where nested objects remain shared references, e.g. via spread syntax) from deep copies (fully independent,...
canonical: https://daily.dev/posts/shallow-vs-deep-copy-in-javascript-rw6zwkasn
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Shallow vs Deep Copy in JavaScript | daily.dev
og:description: A quick explainer distinguishes shallow copies (where nested objects remain shared references, e.g. via spread syntax) from deep copies (fully independent,...
og:url: https://daily.dev/posts/shallow-vs-deep-copy-in-javascript-rw6zwkasn
og:image: https://api.daily.dev/og/posts/rW6zWkaSn.png
og:image:alt: Shallow vs Deep Copy in JavaScript
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Shallow vs Deep Copy in JavaScript

**[navya](https://daily.dev/sources/dlrmprw88mjnbukqs8t0w)** · [@navyaak](https://daily.dev/navyaak) · 1 min read · 7 upvotes · 0 comments

## Summary

A quick explainer distinguishes shallow copies (where nested objects remain shared references, e.g. via spread syntax) from deep copies (fully independent, e.g. via structuredClone). Includes a code exercise using Object.assign to demonstrate how mutating a nested property in a shallow copy also affects the original object.

## Content

**Shallow copy** — a new object is created, but nested objects are shared.

eg: let d = { ...a };

**Deep copy** — a completely independent copy is created.

eg: let d = structuredClone(a);

Todo: what will be the output?

```
const original = { a: "1", b: { c: "2" } };
const shallowCopy = Object.assign({}, original);
shallowCopy.a = 3; 
shallowCopy.b.c = 5; object
console.log(original);
```

#javascript #js #developers

---

Tags: [#javascript](https://daily.dev/tags/javascript)

[View this post on daily.dev](https://daily.dev/posts/shallow-vs-deep-copy-in-javascript-rw6zwkasn)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"DiscussionForumPosting","mainEntityOfPage":"https://daily.dev/posts/shallow-vs-deep-copy-in-javascript-rw6zwkasn","headline":"Shallow vs Deep Copy in JavaScript","text":"A quick explainer distinguishes shallow copies (where nested objects remain shared references, e.g. via spread syntax) from deep copies (fully independent, e.g. via structuredClone). Includes a code exercise using Object.assign to demonstrate how mutating a nested property in a shallow copy also affects the original object.","url":"https://daily.dev/posts/shallow-vs-deep-copy-in-javascript-rw6zwkasn","datePublished":"2026-08-28T16:10:32.714Z","dateModified":"2026-08-28T16:50:07.290Z","author":{"@type":"Person","name":"navya","url":"https://daily.dev/navyaak","image":"https://media.daily.dev/image/upload/s--vM6dTj_h--/f_auto/v1786267696/avatars/avatar_DLRmpRw88MjNBUKqs8T0W?_a=BAMAMicg0","description":"Software Engineer","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":380}},"image":"https://media.daily.dev/image/upload/s--dx-FT7nm--/f_auto/v1787933432/posts/rW6zWkaSn?_a=BAMAMicg0","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":7},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"isPartOf":{"@type":"WebPage","url":"https://daily.dev/sources/dlrmprw88mjnbukqs8t0w","name":"navya"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"navya","item":"https://daily.dev/sources/dlrmprw88mjnbukqs8t0w"},{"@type":"ListItem","position":3,"name":"Shallow vs Deep Copy in JavaScript"}]}
```

