ES6 Objects | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 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 ответ
+ 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