Trouble With Destructuring Assignment


I was running through this exercise and found that if you declare both a min and max in your call to destructure that you will fail this.

I have already found the way to pass

const {tomorrow : {max : maxOfTomorrow} = forecast;

But would it not be best practice to declare all variables when doing this so that they are stored together? This is how it is done in the example and I am just looking for some insight.

Thank you!

Your code so far

  today: { min: 72, max: 83 },
  tomorrow: { min: 73.3, max: 84.6 }

function getMaxOfTmrw(forecast) {
  "use strict";
  // change code below this line
  const {tomorrow : {min: minOfTomorrow, max: maxOfTomorrow}} = forecast; // change this line
  // change code above this line
  return maxOfTomorrow;

console.log(getMaxOfTmrw(LOCAL_FORECAST)); // should be 84.6

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36.

Link to the challenge:

That is what makes destructuring so useful. You only destructure what you need. There is no need to destructure the other properties if they are not needed for the problem at hand.

1 Like

Exactly what I was wanting to know! Thank you very much!