JavaScript - Math.max() Method
The JavaScript Math.max() method returns the largest of the zero or more numbers given as input parameters, or NaN if any parameter is not a number and can not be converted into a number.
Syntax
Math.max(value1, value2, ...)
Parameters
value1, value2, ... |
Specify zero or more numbers among which the largest value need to be returned. |
Return Value
Returns the largest of the given numbers, or NaN if any parameter is not a number and can not be converted into a number.
Example:
In the example below, Math.max() method is used to find out the largest of the given numbers.
var txt; txt = "Math.max(10, 30, 20, 10, 90) : " + Math.max(10, 30, 20, 10, 90) + "<br>"; txt = txt + "Math.max('10', '30', '20', '10') : " + Math.max('10', '30', '20', '10') + "<br>"; txt = txt + "Math.max('10', '30', 20, '10') : " + Math.max('10', '30', 20, '10') + "<br>"; txt = txt + "Math.max('10', 'x', 20, '10') : " + Math.max('10', 'x', 20, '10') + "<br>";
The output (value of txt) after running above script will be:
Math.max(10, 30, 20, 10, 90) : 90 Math.max('10', '30', '20', '10') : 30 Math.max('10', '30', 20, '10') : 30 Math.max('10', 'x', 20, '10') : NaN
❮ JavaScript - Math Object