How to use the function Math.max() to get the largest of zero or more numbers in JavaScript

1 Answer

0 votes
document.write("Math.max(1, 2) = " + Math.max(1, 2) + "<br />");
document.write("Math.max(-1, -2) = " + Math.max(-1, -2) + "<br />");
document.write("Math.max(-1, 2) = " + Math.max(-1, 2) + "<br />");
document.write("Math.max(28, 982, 512) = " + Math.max(28, 982, 512) + "<br />");
document.write("Math.max(3, 2, 5, 4, 1) = " + Math.max(3, 2, 5, 4, 1) + "<br />");
document.write("Math.max() = " + Math.max() + "<br />");
document.write("Math.max(10) = " + Math.max(10) + "<br />");

 
/*
run

Math.max(1, 2) = 2
Math.max(-1, -2) = -1
Math.max(-1, 2) = 2
Math.max(28, 982, 512) = 982
Math.max(3, 2, 5, 4, 1) = 5
Math.max() = -Infinity
Math.max(10) = 10
 
*/

 



answered Aug 4, 2016 by avibootz
...