Home >Web Front-end >JS Tutorial >How to use min function
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.
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!