Home >Web Front-end >JS Tutorial >How to find the minimum value in javascript
In JavaScript, you can use the min() method of the Math object to find the minimum value. This method can return the minimum value among zero or more values. The syntax format is "Math.min(value 1, value 2, value 3,..., value N) "; if any parameter cannot be converted to a numerical value, "NaN" is returned.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
In javascript, you can use the min() method of the Math object to find the minimum value.
Let’s learn about it through an example:
console.log(Math.min(5,10)); console.log(Math.min(0,150,30,20,38)); console.log(Math.min(-5,10)); console.log(Math.min(-5,-10)); console.log(Math.min(1.5,2.5));
Output:
Explanation:
Math.min() Returns the minimum of zero or more values.
Syntax
Math.min(n1,n2,n3,...,nX)
Return value:
The smallest number among the given values.
Description:
Since min is a static method of Math, it should be used like this: Math.min(), not as a method of the Math instance you created (Math is not a constructor).
If there are no parameters, the result is Infinity.
If any parameter cannot be converted to a numeric value, the result is NaN.
[Related recommendations: javascript learning tutorial]
The above is the detailed content of How to find the minimum value in javascript. For more information, please follow other related articles on the PHP Chinese website!