+ 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.

15th Feb 2022, 12:05 AM
TahitišŸŒCastillo
TahitišŸŒCastillo - avatar
1 Answer
+ 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.
15th Feb 2022, 12:25 AM
TahitišŸŒCastillo
TahitišŸŒCastillo - avatar