← TechnologyThe essentials of

Object.assign(): later source can overwrite field

Publisher: ResumeMaker • 1 source

Published: 22 Oct 2026 13:13 · Updated: 22 Oct 2026 13:13

AI source check: 21 Oct 2026 12:40. This is not editorial approval.

In a few sentences

In brief

The operation changes the target object and copies shallowly.

Useful to know

Object.assign() copies its own enumerable properties to a target object. In Object.assign({}, {mode: "light"}, {mode: "dark"}), the final mode is "dark". The later source overwrites the same key . [1]

An empty first object is a conscious choice if you don't want to change the first set of settings. The nested objects do not merge recursively and do not clone deeply. Before combining a configuration, decide whether the target is a shallow substitution or an actual aggregation of nested fields. Function names should reflect this difference.

Sources

For further detail and to check the information:

  1. [1] MDN — Object.assign ↗