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.
Also covered in
What to know first
- accessor methodAn accessor method or function is a callable that reads, computes, or assigns a value associated with a property, field, or data element.
- enumerable propertyAn enumerable property is a JavaScript object property whose enumerable descriptor attribute determines whether it is included in property enumeration.
- functionA function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.
- objectAn object is a distinct entity represented or manipulated within a computational system, typically as a value, data structure, resource, or instance of a type.
Related concepts
- objectuses · An object is a distinct entity represented or manipulated within a computational system, typically as a value, data structure, resource, or instance of a type.
- enumerable propertyuses · An enumerable property is a JavaScript object property whose enumerable descriptor attribute determines whether it is included in property enumeration.
- copy-on-writeused by · Copy-on-write is a technique that shares data until modification requires creating an independent copy, preserving the original for existing users.
- default valueaddresses · A default value is a predefined value automatically applied when no explicit value is supplied or specified.
- mutationcontrasts with · Mutation is a change to an existing entity, such as a value, state, data structure, or candidate 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.
Questions about Object.assign
What is 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.
Which Manning books explain Object.assign?
The Joy of JavaScript and Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond.
What should I know before learning Object.assign?
Manning books that teach Object.assign usually introduce accessor method, enumerable property, function and object first.
What is the difference between Object.assign and mutation?
Object.assign is a JavaScript static method that copies enumerable own properties from source objects to a target object and returns the target. Mutation is a change to an existing entity, such as a value, state, data structure, or candidate representation.
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.

