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

1 Answer

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

 
/*
run

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

 



answered Aug 4, 2016 by avibootz
...