Math min() Method - Javascript Math

Javascript examples for Math:min

Description

The min() method returns the number with the lowest value.

Syntax

min(n1, n2, n3, ..., nX );

Parameter Values

Parameter Description
n1, n2, n3, ..., nX Optional. One or more numbers to compare

Return Value:

A Number, which is the lowest 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 lowest value:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p>Click the button to compare numbers and return the lowest.</p>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from  w  ww  . j a v  a 2s  .co m
    var a = Math.min(5, 10);
    var b = Math.min(0, 150, 30, 20, 38);
    var c = Math.min(-5, 10);
    var d = Math.min(-5, -10);
    var e = Math.min(1.5, 2.5);

    var x = a + "<br>" + b + "<br>" + c + "<br>" + d + "<br>" + e;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials