DEV Community

Discussion on: Difference between Object.assign() and just assign

Collapse
 
utsavladani profile image
Utsav Ladani • Edited

Here Object.assign() copy the value of first level's key-value pair, but if your key-value pair's value is object then it will assign by address.
Here is example.

let x = { "a":{c:10}, "b":100};
let z = {};
Object.assign(z,x);
z.b = 1000;
z.a.c = 50;
console.log(x);

// {a: {c: 50}, b: 100}
Enter fullscreen mode Exit fullscreen mode

Remember this for better understanding.