Object.assign
Object.assign is a JavaScript static method that copies enumerable own properties from source objects to a target object and returns the target.
The Joy of JavaScript
Object.assign is a JavaScript built-in function that copies enumerable own properties from source objects to a target object.
- How it is used
- Composes configuration, API responses, shallow clones, and mixins by copying independent property bags into one object.
- How deep it goes
- Explains enumerability, ownership, precedence, shallow copying, and setter behavior, while stopping short of recursive cloning.
- Examples
- Uses configuration defaults, API-response merging, shallow cloning, non-enumerable properties, inherited properties, and mixin method conflicts.
- What you can do after
- Apply it to construct composed objects, merge defaults, create shallow clones, and predict conflicts between source properties.
Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond
A JavaScript static method that copies the values of enumerable own properties from one or more source objects to a target object and returns that target object.
- How it is used
- Uses Object.assign to fill default options and extend objects with additional properties.
- How deep it goes
- Works through source order, target mutation, setters, and own enumerable properties without descending into specification algorithms.
- Examples
- Uses pizza-tracking map options, enhanced spaceships, a validating setter, and an array copied into an object.
- What you can do after
- Apply it via Object.assign to set defaults, extend objects, and choose whether the original object is mutated.
Related concepts
- objectuses · A computational object is a runtime entity or structured value representing data, state, or a resource, with properties or operations defined by its programming model.
- enumerable propertyuses · An enumerable property is a JavaScript object property whose enumerable descriptor attribute determines whether it is included in property enumeration.
- setuses · A set is a collection of unique elements in which membership is determined by whether an element is present, not by duplicate occurrences.
- default valueaddresses · A default value is a predefined or automatically supplied value used when an expected input, argument, field, or configuration setting is omitted or unspecified.
- mutationcontrasts with · Mutation is an alteration to an existing value, state, data structure, or representation.
- Object.definePropertycontrasts with · Object.defineProperty is a JavaScript built-in method that creates or modifies an object property using an explicitly specified property descriptor.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

