Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Why is Math.min () larger than Math.max ()

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you why Math.min() is bigger than Math.max(). The content is concise and easy to understand. It will definitely make your eyes shine. I hope you can gain something from the detailed introduction of this article.

Consider the following code:

var min = Math.min();

var max = Math.max();

console.log(min < max);

As a general rule of thumb, this code should print true, since the minimum should be less than the maximum. But when we run this code, it magically outputs false.

Why is this happening?

We'll have to check MDN's documentation.

The Math.min() function returns the smallest of zero or more numbers.

Math.min has zero or more parameters. If multiple arguments are easy to understand, return the smallest of the arguments.

What if there are zero parameters? The document reads:

If no arguments are given, the result is Infinity.

If at least one of arguments cannot be converted to a number, the result is NaN.

If there are no arguments, return Infinity. What is Infinity? Infinity is an attribute of the global object in javascript, or an attribute of the window object in the browser environment, indicating infinity.

Math.max() returns-Infinity when no arguments are passed.

Math.min() is greater than Math.max().

That's why Math.min() is bigger than Math.max(). Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report