JavaScript Math.max()
Definition and Usage
The Math.max() method returns the number with the highest value.
Tip: Math.min() returns the number with the lowest value.
More Examples
let a = Math.max(5, 10);
let b = Math.max(0, 150, 30, 20, 38);
let c = Math.max(-5, 10);
let d = Math.max(-5, -10);
let e = Math.max(1.5, 2.5);
Try it Yourself »
Browser Support
Math.max()
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
Syntax
Math.max(n1, n2, n3, ..., nX)
Parameters
Parameter | Description |
---|---|
n1, n2, n3, ..., nX | Optional. One or more numbers to compare |
Return Value
: | A number, representing the highest number of the arguments. -Infinity if no arguments are given. NaN if one or more arguments are not a number. |
---|