Junior From PDF JavaScript JavaScript

What is the difference between shallow copy and deep copy?

Type Description

Shallow

Copy

Copies top-level properties only

Deep Copy Copies all nested objects too

Follow me on LinkedIn:

Example:

const obj = { a: { b: 1 } };
const shallow = { ...obj }; // same reference
const deep = JSON.parse(JSON.stringify(obj)); // new copy

More from JavaScript Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details