English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
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); // 97Test to see‹/›
All browsers fully support the Math.max() method:
Method | |||||
Math.max() | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
n1, n2, n3, ..., nX | Compare one or more numbers |
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 |