marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
2.99k stars 790 forks source link

some observations on ch3 #552

Closed gumbol closed 3 years ago

gumbol commented 3 years ago

on ch3 exercises dabbling with Math.min/max.

I found that if you add two numbers of the same value the function will return that same value. instead of maybe undefined. unless a number can be larger or smaller than itself. console.log(Math.min(2,2)) // -> 2

marijnh commented 3 years ago

Indeed, that's how Math.min is defined. It would be terribly impractical if it were to return undefined in this case.

gumbol commented 3 years ago

yes i think so too. my edited comment i mentioned another option which is to return "same value" or "equal". looking up this further on mdn it turns out the definition of math.min returns a value that is <= to the value its compared to. which is treated as a boundary.