JavaScript MIN

The JavaScript MIN function is a Math function, which returns the Minimum or Smaller value from the specified set of expression. The syntax of the JavaScript MIN function is

Math.min(Value1, Value2, ...ValueN);

Value1: It can be a number or a valid numerical expression.

  • If we provide Zero arguments, MIN function returns Positive Infinity
  • If the value argument is a positive or negative integer, the MIN function will return the Output.
  • Any of the value is not a number, and then MIN function returns NaN.
  • If it is Null, the MIN function converts Null value to Zero.

JavaScript MIN Function Example

The JavaScript MIN function is used to return the Minimum or Smaller value from the given set of numbers. In this example, We are going to find the Minimum value from a different set of data types and display the output

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript MIN Function </title>
</head>
<body>
  <h1> JavaScript MIN Function </h1>
  <p id = "Pos"></p>
  <p id = "Neg"></p>
  <p id = "Dec"></p>
  <p id = "Neg_Dec"></p>
  <p id = "Str"></p>
  <p id = "Str1"></p>
  <p id = "Null"></p>
  <p id = "Multi"></p>
  <script>
    document.getElementById("Pos").innerHTML = Math.min(10, 2, 3);
    document.getElementById("Neg").innerHTML = Math.min(-1, 2, -9, -7);
    document.getElementById("Dec").innerHTML = Math.min(12.50, 4.05, 9.35, 14.58);
    document.getElementById("Neg_Dec").innerHTML = Math.min(-3.10,-6.05, -22.04, -15.08);
    document.getElementById("Str").innerHTML = Math.min(2, "3", "1", 9);
    document.getElementById("Str1").innerHTML = Math.min(2, "String");
    document.getElementById("Null").innerHTML = Math.min(4, null, 5, 9);
    document.getElementById("Multi").innerHTML = Math.min();
  </script>
</body>
</html>
JavaScript MIN Function

We used the MIN Function on the String value. The following statement converts the “3” and “1” to integers and return the output.

document.getElementById("Str").innerHTML = Math.min(2, "3", "1", 9);

Next statement, We tried JavaScript MIN Function on “String”. As we said before, it returns NaN (Not a Number) as output

document.getElementById("Str1").innerHTML = Math.min(2, "String");

We used MIN Math Function along with Null value. Here the null argument is converted to Zero.

document.getElementById("Null").innerHTML = Math.min(4, null, 5, 9);

Last, We tried JS MIN Function without arguments (Zero arguments), and this will return Infinite