It doesn’t. Functions are not locked to only work for only one object. The destructuring takes the min and max properties from whatever object is passed into the function.
Max certainly is not undefined inside of the function. It is defined as a function argument. That syntax means that the min and max values are extracted from what every object is passed into the function when the function is called.
It hasn’t been passed. So right now the program should do nothing unless the values are passed behind the scenes like a comment in previous thread suggested.
Behind the scenes half is called by passing stats .
half(stats);
Max and min are just any two variables to the function whose value are undefined only when you define it or pass something to it it gets defined inside the function.
For it to be defined inside the function, you have to create an additional line of code where you pass the object or values of max and min to the function.
Totally understandable. I too used to get stuck/confused about small things sometimes. That’s why the Freecodecamp forum community is here to help us here and there giving hints suggestions pushing small simple ideas etc.
a) So, correct me if I’m wrong…but the functions sole purpose in this case…is merely to do the calculation for whatever arguments were passed to it? (in this case min and max)
b) What I also don’t understand is…because we’re dealing with objects here shouldn’t the curly brackets be incorporated within the parameter too?
could you kindly answer (b) please? Imo…because min and max come from an object surely curly brackets should also be incorporated within the parameters too?
eg: ({…})
yeah, I see the difference with curly brackets inclusive you use properties ,but in the first case you won’t be specific on any properties though, not like the 2nd case where it’s specified on 2 (in other words we want information only on 2 properties!)
All this syntax means is that an object will be passed to the function and the function should extract the min and max properties of the object. Absolutely nothing is stated about any other properties the object may or may not have.
Calling and defining the function are completely separate issues. What object we pass into the function when we call the function has absolutely nothing to do with how we have defined the function.