**Tell us what’s happening:
Help me please with this code.
Your code so far
const HIGH_TEMPERATURES = {
yesterday:75,
today:77,
tomorrow:80,
};
const {today,tomorrow} = HIGH_TEMPERATURES;
console.log(yesterday);
console.log(today);
console.log(tomorrow);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36
.
Challenge: Use Destructuring Assignment to Extract Values from Objects
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
You are going to get an error as long as you have console.log(yesterday)
in there. You haven’t declared a variable named yesterday
so that statement will throw an error.
1 Like
Thanks you for the assistance. I appreciate.
I have debugged the code. it’s work thanks
1 Like
Johnny2020:
const HIGH_TEMPERATURES = {
yesterday:75,
today:77,
tomorrow:80,
};
// Added yesterday to the destructured keys
const { today, tomorrow, yesterday } = HIGH_TEMPERATURES;
// After destructuring, the value is assigned to the
// associated key/variable i.e. yesterday log 75
console.log(yesterday);
console.log(today);
console.log(tomorrow);
// Trying to reassign would fail since they are const
//assigned.
// Interesting enough, HIGH_TEMPERATURES.yesterday = 0
// destructured yesterday will still be 75 this has to do
// with references and other things under the hood.
See the Coded section. I hope it is helpful.
Thanks, it’s work! I am happy you help.
1 Like