JavaScript Math.max()

Example

let x = Math.max(5, 10);
Try it Yourself »

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 »

Description

The Math.max() method returns the number with the highest value.



Syntax

Math.max(n1, n2,...)

Parameters

Parameter Description
n1, n2,... Optional.
One or more numbers to compare.

Return Value

Type Description
NumberThe highest number of the arguments.
-Infinity if no arguments are given.
NaN if one of the arguments is not a number.


Browser Support

Math.max() is an ECMAScript1 (ES1) feature.

ES1 (JavaScript 1997) is fully supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.