The max() method returns the number with the highest value.
The max() method returns the number with the highest value.
Math.max(n1,n2,n3, ..., nX)
Parameter | Require | Description |
---|---|---|
n1, n2, n3, ..., nX | Optional. | One or more numbers to compare |
A Number, representing the highest number of the arguments
-Infinity if no arguments are given
NaN if one or more arguments are not numbers
Return the number with the highest value:
//return the highest number of 5 and 10. console.log(Math.max(5, 10));//from w w w . j ava 2s. c o m //Return the number with the highest value: var a = Math.max(5, 10); var b = Math.max(0, 150, 30, 20, 38); var c = Math.max(-15, 10); var d = Math.max(-15, -10); var e = Math.max(1.15, 2.5); var x = a + "\n" + b + "\n" + c + "\n" + d + "\n" + e; console.log(x);