Object.assign copies the properties of one or more source objects onto a target object and returns that target. It's the classic way to merge objects, apply defaults, or shallow-clone with Object.assign({}, source) — and it copies only what a source owns and exposes.
Implement objectAssign(target, ...sources). For each source (left to right), copy its own enumerable properties — both string-keyed and symbol-keyed — onto target, mutating it. Skip null/undefined sources, let later sources overwrite earlier ones, and return target.
function objectAssign(target, ...sources) {
// mutates target with each source's own enumerable properties;
// returns target.
}
objectAssign({ a: 1 }, { b: 2 }); // { a: 1, b: 2 }
objectAssign({}, { a: 1 }, { a: 2 }); // { a: 2 } — later source wins
objectAssign({ a: 1 }, null, { b: 2 }); // { a: 1, b: 2 } — null skipped
const clone = objectAssign({}, original); // shallow copy of `original`
null and undefined sources contribute nothing (no error).null/undefined target throws a TypeError.