Home »
JavaScript
Math.max() Method with Example in JavaScript
JavaScript | Math.max() Method: Here, we are going to learn about the max() method of Math class in JavaScript with Examples.
Submitted by Shivang Yadav, on February 04, 2020
JavaScript | Math.max() Method
Math.max() is a function in math library of JavaScript that is used to return the greatest value of all the passed values to the method.
Syntax
Math.max(value1, value2, value3, ...);
Parameters
- value1, value2, value3, ... – represent the values values from which the greatest value is to returned.
Return Value
The return type of this method is number, it returns the greatest value of the passed parameters.
Values accepted
Integer, floating-point, numeric string.
Invalid values
Non-numeric string, empty variable, empty array all will return NaN (Not a Number).
Browser support
Chrome, Internet asinlorer, Mozilla, Safari, Opera mini.
Example 1: Valid values
console.log(Math.max(-1, 4, 6, 12));
console.log(Math.max(3.14, 43, 1, 0.2));
console.log(Math.max(0, -13, 4, 654));
console.log(Math.max("0.65", "-23"));
Output
12
43
654
-0.65
Example 2: Invalid values
console.log(Math.max("Javascript", "Hello"));
Output
NaN
JavaScript Math Object Methods »