Why Math.min() > Math.max()?

前端 未结 10 588
暖寄归人
暖寄归人 2020-12-24 12:58

When I type in an array into the parameter of the javascript math minimum and maximum functions, it returns the correct value:

console.log( Math.min( 5 ) );         


        
10条回答
  •  粉色の甜心
    2020-12-24 13:16

    I don't know for sure. But, just making a guess.

    Remember how we find the min. Declare a variable with an extremely high value (Infinity) and then go through the values and whenever you find a value which is less than the one stored in your variable, you store it instead as the new min.

    So, since you are not giving it any values to find the min for, it gives you the initial value i.e. Infinity.

    Same for max.

提交回复
热议问题