English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Math.max() Method

 JavaScript Math Object

Math.max()The method returns the largest number.

If no parameters are provided, the result is-Infinity.

If at least one parameter cannot be converted to a number, the result is NaN.

Since max() is a static method of Math, you always use it asMath.max(),instead of using it as a method of the created Math object.

Syntax:

Math.max(n1, n2, n3, ..., nX)
Math.max(10, 20); //  20
Math.max(-10, -20);   // -10
Math.max(1, 3, 2);//  3
Math.max(4, 3, 7, 12);//  12
Math.max(5, 2, 2, 4, 97, 26); //  97
Test to see‹/›

Browser Compatibility

All browsers fully support the Math.max() method:

Method
Math.max()YesYesYesYesYes

Parameter Value

ParameterDescription
n1, n2, n3, ..., nXCompare one or more numbers

Technical Details

Return Value:Returns the largest number in the given numbers. If at least one parameter cannot be converted to a number, it returnsNaN
JavaScript Version:ECMAScript 1

 JavaScript Math Object