美文网首页
Math.max() < Math.min()

Math.max() < Math.min()

作者: 吴晗君 | 来源:发表于2019-05-22 19:51 被阅读0次
console.log(Math.max()) // -Infinity
console.log(Math.min()) // Infinity

为什么这么设计呢?因为在Math.max这个方法是用来比较大小的,默认比较列表中第一个数就是-Infinity,这个值和其他数比较不会影响结果。所以当没有其他参数传入时,-Infinity就是最大的。Math.min同理。

相关文章

网友评论

      本文标题:Math.max() < Math.min()

      本文链接:https://www.haomeiwen.com/subject/pakpzqtx.html