JavaScriptIntermediate#objects

What is the difference between shallow copy and deep copy?

A shallow copy duplicates the top level while nested references stay shared, so mutating a nested value affects both. A deep copy recursively duplicates everything.

Example
const a = { n: { v: 1 } };
const s = { ...a };
s.n.v = 9;
a.n.v; // 9 — shared
const d = structuredClone(a);

Related Questions

1
JavaScriptBeginner#es6#strings

What are template literals?

Open
2
JavaScriptAdvanced#functions

What is currying?

Open
3
JavaScriptIntermediate#functions

What is a higher-order function?

Open