Language concepts

Immutable update

Try the free JavaScript compiler

Creates new objects along the changed path; preserves the original state when shared branches are not mutated.

Formal Syntax & Structure

javascript syntaxjavascript
{ ...state, nested: { ...state.nested, key: value } }

Working Example

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