In a course, I use destructuring:
const stats = {
max: 56.78,
standard_deviation: 4.34,
median: 34.54,
mode: 23.87,
min: -0.75,
average: 35.85
};
const half = ({min, max}) => (max + min) / 2.0;
I first thought the right syntax would be (which also works):
const half = ({min, max} = stats) => (max + min) / 2.0;
My question is how JS knows in which object to look for min and max and what would happen in the event of another object stats2 having properties min and max as well? I don't understand the behaviour of the code in that case.