Using destructuring on objects within functions

Hello,
So I basically understand destructuring in this way BUT what I don’t get is how JS knows to grab the min max values from the stats object when stats is not mentioned in the function?
Thanks.

  **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}) => {
return (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/100.0.4896.127 Safari/537.36

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

Link to the challenge:

Hello there,

You may have missed this part in the challenge:
“When profileData is passed to the above function, the values are destructured from the function parameter for use within the function.”

So when the function is called, you must give the object as a parameter/ argument.

Thanks I will go back and reread it again. Maybe a few tutorials too. Still a little hazy but I think it’s getting clearer.

1 Like

It doesn’t know anything at all about the the object assigned to the variable stats.

The function definition says “this function accepts an object that has properties with the keys min and max.”

The object assigned to the variable stats happens to have these properties, so if you run the function and pass it stats it will work.