Home > Web Front-end > JS Tutorial > How to use min function

How to use min function

不言
Release: 2019-02-16 17:44:58
Original
7029 people have browsed it

The min() function is used to return the number with the lowest value among the specified numbers. If any parameter is not a number and cannot be converted to a number, the Math.min() function will return NaN. Let's take a look at the specific usage of the min() function.

How to use min function

Let’s first take a look at the basic syntax of the min function

Math.min(value1,value2,...)
Copy after login

Value1, Value2,...: passed to The value of the math.min() function, used to find the minimum value.

Let’s look at specific examples

The code is as follows

When the parameters are positive and negative numbers:

The code is as follows

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
<script type="text/javascript">
    document.write("Output : " + Math.min(10, 32, 2)); 
  document.write("Output : " + Math.min(-10, -32, -1));        
</script>
</body>
</html>
Copy after login

The execution result is as follows:

Output : 1
Output : -32
Copy after login

When no parameters are passed

The code is as follows:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
<script type="text/javascript">
  document.write("Output : " + Math.min());       
</script>
</body>
</html>
Copy after login

The execution result is as follows

Output : -Infinity
Copy after login

When there are parameters in the parameters that cannot be converted to numbers:

The code is as follows

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
<script type="text/javascript">
   document.write("Output : " + Math.min(10,2,NaN));       
</script>
</body>
</html>
Copy after login

The execution result is as follows

Output : NaN
Copy after login

This This article has ended here. For more exciting content, you can pay attention to other related column tutorials on the PHP Chinese website! ! !

The above is the detailed content of How to use min function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template