Use Destructuring Assignment to Extract Values from ObjectsPassed ? need some help understanding

Tell us what’s happening:
ok i know this is correct already. but i am still struggling with is the how of it. how is this destructuring the object?? its not m!king much sense to me in my head.

Your code so far


const HIGH_TEMPERATURES = {
yesterday: 75,
today: 77,
tomorrow: 80
};

// change code below this line

const {today, tomorrow} = HIGH_TEMPERATURES;

// change code above this line

console.log(yesterday) // should be not defined
console.log(today); // should be 77
console.log(tomorrow); // should be 80

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 5.1.1; KFDOWI) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36.

Challenge: Use Destructuring Assignment to Extract Values from Objects

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-extract-values-from-objects

The line above says find properties named today and tomorrow in the object HIGH_TEMPERATURES and assign their values to variables of the same names. That is what destructuring of objects is. You are selecting specific properties from an object and assign the values of those object properties to variables of the same names. It is the same as writing:

const today = HIGH_TEMPERATURES.today;
const tomorrow = HIGH_TEMPERATURES.tomorrow

but much more concise code.

4 Likes

i dontcunderstand tho how is today and tomprrow the value?? this stuff is so confusing. i thought it was the variable.

Objects have properties. Properties have values. Destructuring an object’s properties as shown in your solution, assigns the values of those properties to variables of the same names as the properties.

1 Like

Hello!

Just FYI this fails the ES5 assignment test.

const {today, tomorrow} = HIGH_TEMPERATURES;
// const today = HIGH_TEMPERATURES.today;
// const tomorrow = HIGH_TEMPERATURES.tomorrow