JavaScript max()Method
Example
Return the number with the higher value of two specified numbers:
Math.max(5,10);
Output:
10
Try it Yourself »
Definition and Usage
The max() method can return the number with the higher value of two specified numbers.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the max() method
Syntax
Math.max(n1,n2,n3,...,nX)
Parameter Values
| Parameter | Description |
|---|---|
| n1,n2,n3,...,nX | Optional. One or more values. Before ECMAScript v3, this method had only two parameters. |
Return Value
| Type | Description |
|---|---|
| Number | The largest value among the parameters. If there are no parameters, it returns -Infinity. If any parameter 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 demonstrate 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);
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, andeOutput:
10
150
10
-5
2.5
150
10
-5
2.5
Try it Yourself »
Other Extensions
JavaScript Math Object