How JS knows that I am calling from stats object?

Tell us what’s happening:
Describe your issue in detail here.

The code below is correct but I am wondering about how JavaScript knows that I am calling max & min from stats?

  **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/99.0.4844.74 Safari/537.36

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

Link to the challenge:

Because stats is being passed into the half function when it is called. The test is calling the function as:

const halfStats = half(stats);

But the tests could also create an entirely different object (let’s call it moreStats) and as long as moreStats has the properties min and max then it will work as well.

const halfMoreStats = half(moreStats);

Using destructuring doesn’t change the way the function works. It is merely a syntactic shortcut for grabbing values out of the object passed into it.

1 Like

Thank you for the help. I got the point.

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