How can it know that min and max are stats's attributes, I didn't understand this point

Tell us what’s happening:

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

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

Link to the challenge:

Not sure I understand the question.

To know what object is being used for the destructuring you have to look at the function call.

half(stats);

You know what stats is by looking at the code (i.e. an object) and by looking at the function definition you can see which properties are being used for the parameters.

I assume by “it” you mean the runtime. The runtime “knows” it because the function is passed the object as an argument.

it doesn’t know
but this is a function, and when you call it with an object as argument, it takes the properties from that object
half(stats)

this function is meant to work with any object which holds the properties max and min. Even before you edit the entries, it was not associated with the stats object. Its properties and argument were called stats, but they were local

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