Object static methods

Object.assign()

Try the free JavaScript compiler

Copies enumerable own string and symbol properties from sources to target in order using property reads and writes. Mutates and returns target. Copying is shallow and can execute getters or setters. Nullish sources are skipped; nullish target throws.

Formal Syntax & Structure

javascript syntaxjavascript
Object.assign(target, ...sources)

Parameters & Attributes

NameTypeDescription
targetobject or convertible primitiveDestination.
sourcesvaluesSources to copy, in order.

Return Value

Object

Destination object.

Working Example

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