ES6 Destructuring- How does this code know to retrieve values from another object(stat)?

Hello everyone,

I am confused on lesson 17 of ES6 in the JavaScript Algorithms and Data Structures certification. We are using restructuring in one line, but I don’t understand how the code we are changing can actually retrieve the max and min values from the stat object. Like we aren’t referring to stat or calling on it or anything in the const half declaration. My code is correct, I just need help understanding it.

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/86.0.4240.75 Safari/537.36.

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

Link to the challenge:

Destructuring is like an object filter, you pass anything with {min, max} keys, and get those variables.

If you look at the bottom left corner, they call the function to test the code


So that’s when the filtering happens, and you extract min and max, if they exist in the stats object…

tbh, there are so many exact same questions as you that probably the exercise is just unclear. But remember you should search before asking. Well, it will be quicker for you:


Oh, okay I see, thank you so much!

1 Like