Why does
Math.min([])
evaluate to0
?
Because the spec says so:
Math.min
casts each parameter to a number using…
ToNumber
casts objects to a number using…
ToPrimitive
casts objects to primitive values using…
[[Default Value]]
internal method converts objects to primitives based on their hint parameter.
The default hint for all objects is string. Which means the array gets converted to a string, which for []
is ""
.
ToNumber
then converts ""
to 0
, per the documented algorithm
Math.min
then takes the only parameter and returns it, per its algorithm.