Favorites

JavaScript Object.assign() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Object.assign()
JavaScript Object Static methodThis method is supported by all modern browsers.
Updated 28th November 2026

The Object.assign() static method copies the properties of one or more source objects onto a target object and returns the target.

Description

The Object.assign() static method copies all own enumerable properties from the source objects to the target object, later sources overwriting earlier ones. It changes and returns the target, so Object.assign({}, a, b) creates a merged copy.

The copy is shallow: nested objects are shared, not duplicated. In modern code, object spread syntax, { ...a, ...b }, does the same thing for new objects. For a deep copy, use structuredClone().

Only own, enumerable properties are copied, including symbol-keyed ones; getters are run and their values copied, rather than the getter itself. Properties are assigned in order, so if a setter on the target throws, the copy stops part-way. null and undefined sources are skipped without error.

Syntax

Object.assign(target, source1, source2, ...)

Parameters

  • targetThe object to copy properties into. It is changed and returned.
  • source1, source2, ...Objects whose own enumerable properties are copied, in order.

Return Value

The target object.

Example

const defaults = { theme: 'light', size: 'm' };
const prefs = { size: 'l' };
console.log(Object.assign({}, defaults, prefs));

const target = { a: 1 };
Object.assign(target, { b: 2 });
console.log(target);

Browser Support

The following information will show you the current browser support for the Object.assign() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee