+ 1
Object.assign() in ES6 (What is the output of this code?)
What is the output of this code? const obj1 = { a: 0, b: 2, c: 4 }; const obj2 = Object.assign({c: 5, d: 6}, obj1); console.log(obj2.c, obj2.d);
5 Antworten
+ 3
https://code.sololearn.com/WKPdKnn9WC2a
the output of this code is :
4 6
+ 3
The assign() copies key-value pairs into a new array.
d has a value of 6, and
c has a value of 5 from the first argument,
however, c is later rewritten as 4, from second argument obj1
That's why the console logs "4 6" instead of "5 6"
+ 1
46 is the accepted answer, but should be 4 6
+ 1
46
- 1
4 6