Object Destructuring confusion

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

How does Javascript know the object I want to destructure without me specifying it? I don’t understand this.

the solution was said to be :

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

But, I have no idea how you can just write max, min, etc and javascript pulls it from the Stats object?

if I have two objects, or four, or five. And say I have two objects that both have a min / max key in them. How would javascript know / understand or attempt to pull from the stats object for the destructuring? And why / how does it work? I failed this and had to search for the answer because I’m trying to use “stats” specifically somewhere in order to de-structure, and I can’t understand why you don’t have to use it. Can anyone provide some clarity on this?

Link to the challenge:

There is zero connection with a specific object. Whatever is passed in as the function argument is destructured.

1 Like

Ahhhhhh! Got it, the object is being passed as an argument to the function and then being de-structured based off of the keys used in de-structuring in other words?

Don’t know why I didn’t realize this after doing React for some while, just brain fog I guess.

Thanks!

1 Like

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