On this page
  1. Object.assign
  2. Signature & Overview
  3. Notes & Pitfalls
  4. Example

Object.assign

Prev: hasOwn | Up: Object | Next: create
Rel: Object, Object & Reflect Guide
Ref: MDN Web Docs — Object.assign
Tags: #public #web #javascript #builtins #object #tier/standard


Signature & Overview

Object.assign(target, ...sources)

Copies own enumerable properties from one or more sources into target (mutating target).

Notes & Pitfalls

Example

const defaults = { host: "localhost", port: 8080 };
const cfg = Object.assign({}, defaults, { port: 9000 });
console.assert(defaults.port === 8080 && cfg.port === 9000);

Linked from

Related notes