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

How to use min function

不言
不言Original
2019-02-16 17:44:587069browse

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,...)

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>

The execution result is as follows:

Output : 1
Output : -32

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>

The execution result is as follows

Output : -Infinity

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>

The execution result is as follows

Output : NaN

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!

Statement:
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
Previous article:How to use max functionNext article:How to use max function

Related articles

See more