I thought that when I gave a console.log(HIGH_TEMPERATURES) the names of the properties would change and be like:
Const HIGH_TEMPERATURES = {
yesterday: 75,
highToday: 77,
tomorrow: 80,
}
Anyone can explain me why it’s useful to Use Destructuring Assignment to Assign Variables from Objects ?
we do what you did above. It accomplishes the same thing but using destructuring, it is only one line and cleaner. There is nothing you can do with destructuring that you can’t do without it. But it saves you lines and makes for cleaner code. Even if you don’t like it for some reason, you still need to know it because you will see a lot of it.
you can also destructure multiple layers down, e.g., lets say I have destructured foo from an object, but foo is also an object that has a value I want so I then proceed to destructure that which looks like
const obj = { foo: {bar: 1}, };
const {foo: { bar } } = obj;
console.log(bar) // 1
//if you wanted to have the value bar with a different name its also pretty similar has to how you would normally do that
const obj = { foo: {bar: 1}, };
const {foo: { bar: baz } } = obj;
console.log(baz) // 1