Object concepts

Shallow copy

Try the free JavaScript compiler

Creates a new outer container while copying member values. Nested objects retain their identities. A shallow copy does not recursively duplicate data or necessarily preserve descriptors.

Formal Syntax & Structure

javascript syntaxjavascript
array.slice() or Object.assign({}, source)

Working Example

Example Snippetjavascript
const a={nested:{n:1}}; const b=Object.assign({},a);console.log(a===b,a.nested===b.nested);
JavaScript Reference