ES6 - Use Destructuring Assignment to Pass an Object as a Function's Parameters

Tell us what’s happening:
How does the code know that it should get the value from the stats variable without getting its name? Also, why are there curly brackets needed for the properties?

Your code so far

const stats = {
  max: 56.78,
  standard_deviation: 4.34,
  median: 34.54,
  mode: 23.87,
  min: -0.75,
  average: 35.85

// Only change code below this line
const half = ({max, min}) => (max + min) / 2.0; 
// Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: ES6 - Use Destructuring Assignment to Pass an Object as a Function’s Parameters

Link to the challenge:

It doesn’t. Any variable with the destructured properties will work as a function argument.

but what if there’s another function with the same properties? What will happen then?

That’s unrelated. Declaring a function that uses destructuring has no effect on another function call. It works literally the same way as it used to. This is just a different way to write the arguments list.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.