JavaScript max() Method
Example
Return the number with the larger value among the two specified numbers:
Math.max(5,10);
Output result:
10
Try it »
Definition and Usage
The max() method returns the number with the larger value among the two specified numbers.
Browser support





All major browsers support the max() method.
Syntax
Math.max(
n1
,
n2
,
n3
,...,nX)
Parameter value
| Parameters | Description |
|---|---|
| n1,n2,n3,...,nX | Optional. One or more values. Before ECMAScript v3, this method accepted only two arguments. |
Return Value
| Type | Description |
|---|---|
| Number | The largest value among the arguments. If there are no arguments, it returns -Infinity. If any argument is NaN, or a non-numeric value that cannot be converted to a number, it returns NaN. |
Technical Details
| JavaScript version: | 1.0 |
|---|
More examples
Example
In this example, we will show how to use max() to return the number with the highest value among the specified numbers:
var a=Math.max(5,10);
var b=Math.max(0,150,30,20,38);
var c=Math.max(-5,10);
var d=Math.max(-5,-10);
var e=Math.max(1.5,2.5);
a,b,c,d, and LinkedHashMap, among others. e Output result:
10
150
10
-5
2.5
Try it »
JavaScript Math object