JavaScript min()Method

Math 对象参考手册JavaScript Math Object

Examples

Return the minimum value:

Math.min(5,10);

Output:

5

Try it Yourself »

Definition and Usage

The min() method returns the number with the smallest value among the specified numbers.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the min() method.


Syntax

Math.min(n1,n2,n3,...,nX)

Parameter Values

Parameter Description
n1,n2,n3,...,nX Optional. One or more values. Before ECMAScript v3, this method only had two parameters.

Return Value

Type Description
Number The smallest value among the parameters. If no parameters are provided, Infinity is returned. If any parameter is NaN, or a non-numeric value that cannot be converted to a number, NaN is returned.

Technical Details

JavaScript Version: 1.0


Example

Example

Return the minimum value:

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);

a,b,c,d, andeOutput:

5
0
-5
-10
1.5

Try it Yourself »


Math 对象参考手册JavaScript Math Object

Other Extensions