Destructuring Question: Pass an Object as a Function's Parameters

Tell us what’s happening:
Hi,
Just a side questions…
In codepen, when I console log “half” for the following:

const half = ({max, min}) => (max + min) / 2.0;

It just logs: “const half = ({max, min}) => (max + min) / 2.0;”
instead of “28.015”

Why is 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
};

// change code below this line

const half = ({max, min}) => (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 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36.

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

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-pass-an-object-as-a-functions-parameters

Because it is in the Globale frame half part. I’m not sure but can to be related to the lesson showing you the part that is relevant rather then the actually outcome
Indeed the console.log outcome should be: { max: 56.78, standard_deviation: 4.34, median: 34.54, mode: 23.87, min: -0.75, average: 35.85 } 28.015

1 Like

because half is a function, not a number. If you want to know what half returns you need to call the function, as done in the console.log at the bottom; half(stats)

1 Like