What's the output?
const animals = {};
let dog = { emoji: '馃惗' }
let cat = { emoji: '馃悎' }
animals[dog] = { ...dog, name: "Mara" }
animals[cat] = { ...cat, name: "Sara" }
console.log(animals[dog])You missed this one before
Object keys are converted to strings.
Since the value of dog is an object, animals[dog] actually means that we鈥檙e creating a new property called "[object Object]" equal to the new object. animals["[object Object]"] is now equal to { emoji: "馃惗", name: "Mara"}.
cat is also an object, which means that animals[cat] actually means that we鈥檙e overwriting the value of animals["[object Object]"] with the new cat properties.
Logging animals[dog], or actually animals["[object Object]"] since converting the dog object to a string results "[object Object]", returns the { emoji: "馃悎", name: "Sara" }.
Question 150 路 see the original (opens in a new tab)
or press Enter