+ 1
ES6 Objects
/* I answered incorrectly, then guessed and was correct. Can someone explain the answer, please? */ const obj1 = { a: 0, b: 2, c: 4 }; const obj2 = Object.assign ( { c: 5, d: 6}, obj1); console.log (obj2.c, obj2.d); //Thank you.
1 Resposta
+ 2
@Tahiti🍷Castillo, using the = symbol creates a reference to the base object (in this case, obj1). Any changes intended for a new object (like obj2) mutate the original object (obj1). There is no ‘d’ parameter in obj1, so only the ‘d’ in obj2 could be logged to the console.