---
hide_title: false
hide_table_of_contents: false
pagination_next: null
pagination_prev: null
---
# Object.assign()

The **`Object.assign()`** method
copies all [enumerable](../../globals/Object/prototype/propertyIsEnumerable.mdx)
[own properties](../../globals/Object/hasOwn.mdx) from one or more
_source objects_ to a _target object_. It returns the modified target
object.

## Syntax

```js
Object.assign(target, ...sources)
```

### Parameters

- `target`
  - : The target object — what to apply the sources' properties to, which is returned
    after it is modified.
- `sources`
  - : The source object(s) — objects containing the properties you want to apply.

### Return value

The target object.

## Description

Properties in the target object are overwritten by properties in the sources if they
have the same "key". Later sources' properties overwrite earlier ones.

The `Object.assign()` method only copies _enumerable_ and
_own_ properties from a source object to a target object. It uses
`[[Get]]` on the source and `[[Set]]` on the target, so it will
invoke [getters](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Functions/get) and [setters](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Functions/set). Therefore it
_assigns_ properties, versus copying or defining new properties. This may make it
unsuitable for merging new properties into a prototype if the merge sources contain
getters.

For copying property definitions (including their enumerability) into prototypes, use
[`Object.getOwnPropertyDescriptor()`](../../globals/Object/getOwnPropertyDescriptor.mdx) and
[`Object.defineProperty()`](../../globals/Object/defineProperty.mdx) instead.

Both `String` and `Symbol` properties are copied.

In case of an error, for example if a property is non-writable, a
[`TypeError`](../../globals/TypeError/TypeError.mdx) is raised, and the `target` object is
changed if any properties are added before the error is raised.

> **Note:** `Object.assign()` does not throw on
> [`null`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/null) or [`undefined`](../../globals/undefined.mdx) sources.
