object.assign examples
Example 1: javascript object.assign
const target = { a: 1, b: 2 };
const source = { b: 4, c: 5 };
const returnedTarget = Object.assign(target, source);
console.log(target);
// expected output: Object { a: 1, b: 4, c: 5 }
console.log(returnedTarget);
// expected output: Object { a: 1, b: 4, c: 5 }
Example 2: Object.assign()
const obj1 = {
a: 5,
b: 2
}
const obj2 = Object.assign({a:6 d:7}, obj1);
console.log(obj2);
// output: { a: 5 , b: 2, d:7}