Home >>JavaScript Math Reference >JavaScript max() Method

JavaScript max() Method

JavaScript max() Method

The Math max () Method of the object accepts multiple numbers and returns the largest of zero or more numbers. Generally, It is always used as Math.max() because it is a static method of math. It will return the same if you can pass single number to this function. The result is "-Infinity" if you do not pass any arguments and if at least one of the arguments cannot be converted to a number the result is NaN.

Syntax:
Math.max(value1, value2, ...)

Parameter Values

Parameter Description
n1, n2, n3, ...,nX It is optional. You can compare one or more numbers

Browser Support

Method Chrome Edge Firefox Safari Opera
max() Yes Yes Yes Yes Yes
Here is an example of JavaScript max() Method
<html>
<body>
<button onclick="myMax()">Click me</button>
<p id="max"></p>
<script>
function myMax() {
  document.getElementById("max").innerHTML = Math.max(25, 20);
}
</script>
</body>
</html>
Output:

Example 2:
<html>
<body>
<script type="text/javascript"> 
document.write("Output : " + Math.max()); 
</script> 
</body>
</html>
Output: