Use Destructuring Assignment to Pass an Object as a Function's Parameters - why I am not calling the object?

Tell us what’s happening:
I don’t get why in this case I don’t need to call stats inside the function. Is it because it is the only object that there is?

I use return function half({max, min}) {}, but does it works because there is only an object that has max and min properties and so as good practive I should call stats when using Destructuring Assignment like in the examples, or it just works like that?

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
const half = (function() {
  "use strict"; // do not change this line

  // change code below this line
  return function half({max, min}) {
    // use function argument destructuring
    return (max + min) / 2.0;
  }  // change code above this line

console.log(stats); // should be object
console.log(half(stats)); // should be 28.015

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

Link to the challenge:

1 Like

It worked because stats has max and min properties

And if there is more than one object with those properties?

you passed stats as an argument to the function… what gets passed to the function is the result you get

I have the same question. I don’t see where stats is passed as an argument to the function … only that max and min are passed. But since they are properties of the object “stats”, how does the function know to look in that object?

I found out! last line, console.log(half(stats));

Oh right! So cool! Thanks!