I'm using a generator to create objects, like so:
function* Thing() {
var x = 0;
while (x < 3) {
var rules = [{arr: [1, 2, 3]}, {arr: [1]}, {arr: []}];
yield {
arrayMinimum: Math.min(...rules[x].arr)
}
x++
}
}
var create = Thing();
console.log(create.next().value)
console.log(create.next().value)
console.log(create.next().value) // { arrayMinimum: Infinity } ???
Why is Math.min(...[]) === Infinity
?
Bonus confusion: Math.max(...[]) === -Infinity
???
This is because the arguments-list specified by (...[])
is the empty list of arguments -- i.e., you are doing Math.min()
with no arguments.
The EMCAScript spec for Math.min
states:
If no arguments are given, the result is +∞.
(And, unsurprisingly, it has a similar statement for Math.max
.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With