Home > Article > Web Front-end > How to find the minimum of two numbers in JavaScript
In JavaScript, you can use the min() method of the Math object to find the minimum value of two numbers. This method can return the number with the minimum value among one or more numbers; the syntax format "min( x1,x2)", the parameters x1 and x2 must be numerical values.
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 of two numbers.
Let’s take an example to see how the min() method finds the minimum of two numbers.
var a=Math.min(5,10); var b=Math.min(0,150,30,20,38); var c=Math.min(-5,10); var d=Math.min(-5,-10); var e=Math.min(1.5,2.5); console.log(a); console.log(b); console.log(c); console.log(d); console.log(e);
Output:
Description: Min() method of Math object:
min () method returns the number with the smallest value among the specified numbers.
Syntax:
Math.min(n1,n2,n3,...,nX)
Parameters:
The above is the detailed content of How to find the minimum of two numbers in JavaScript. For more information, please follow other related articles on the PHP Chinese website!