Javascript examples for Math:max
The max() method returns the number with the highest value.
Math.max(n1, n2, n3, ..., nX);
Parameter | Description |
---|---|
n1, n2, n3, ..., nX | Optional. One or more numbers to compare |
A Number, representing the highest number of the arguments, or -Infinity if no arguments are given, or NaN if one or more arguments are not numbers
The following code shows how to return the number with the highest value:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from w w w . j a va2s. c o m*/ var a = Math.max(15, 10); var b = Math.max(01, 150, 30, 20, 38); var c = Math.max(-51, 10); var d = Math.max(-5, -110); var e = Math.max(1.5, 21.5); var x = a + "<br>" + b + "<br>" + c + "<br>" + d + "<br>" + e; document.getElementById("demo").innerHTML = x; } </script> </body> </html>