ES6: Use Destructuring Assignment to Assign Variables from Objects error

Hi, I’m in this challenge and I don’t get why this is throwing an error:

const AVG_TEMPERATURES = {
  today: 77.5,
  tomorrow: 79
};

function getTempOfTmrw(avgTemperatures) {
  "use strict";
  // change code below this line
  const  {tomorrow: tempOfTomorrow} = AVG_TEMPERATURES; // change this line
  // change code above this line
  return tempOfTomorrow;
}

console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79

It works because it is 79 but also throw this error

destructuring with reassignment was used

What am I suppose to do?
Thanks

I already passed the challenge changing AVG_TEMPERATURES by avgTemperatures but I don’t really get why this should be like this

Are you sure you should be destructuring AVG_TEMPERATURES? Also, a quick look in MDN should clarify the correct syntax of object destructuring.

var o = {p: 42, q: true};
var {p, q} = o;

console.log(p); // 42
console.log(q); // true

AVG_TEMPERATURES is an argument of getTempofTmrw() function call.
But when working with data inside a function, it’s not the argument to a function call that should be used, but the parameter inserted in the function getTempOfTmrw()

What is it here?

It’s up to you now to find it.

1 Like

Here are more explanations.

Many documentations and tutorials use the words parameters and arguments interchangeably and it’s confusing.

Here is an example that shows you the difference between the two:

function myFunction(parameter) { 
// parameter gets its value from argument variable passed to myFunction() call.

/* inside a function, the variable parameter 
should be used, not argument. */

/* i.e. You should not use argument variable inside the function */

console.log(parameter) /* output: This is an argument when 
it is passed into myFunction call, and parameter 
when used inside the function */
}

...

var argument = "This is an argument when it is passed into myFunction call, and parameter when used inside the function.";
myFunction(argument);