Object static methods
Object.assign()
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
| Name | Type | Description |
|---|---|---|
| target | object or convertible primitive | Destination. |
| sources | values | Sources 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);