The JavaScript min function is a Math function that returns the Minimum or Smaller value from the specified set of expressions. The syntax of the min function is
Math.min(Value1, Value2, ...ValueN);
Parameters (Value1…ValueN): It can be a number or a valid numerical expression.
Return Value
- If we provide zero arguments, the min function returns Positive Infinity.
- If the value argument is a positive or negative integer, it will return the Output.
- If any value is not a number, it returns NaN.
- If it is Null, it converts the Null value to zero.
JavaScript min Function Example
The min function returns the Minimum or Smaller value from the given set of numbers. In this example, we will find the Minimum value from a different set of data types and display the output.
<!DOCTYPE html>
<html>
<head>
<title> JavaScriptMINFunction </title>
</head>
<body>
<h1> JavaScriptMINFunction </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>
For Str, we used the min Function on the String value. This statement converts the “3” and “1” strings to integers and returns the output.
Next, we tried this method on “String”. As we said before, JavaScript returns NaN (Not a Number) as output. In the following statement, we used this math method along with a Null value. Here, the null argument is converted to Zero.
Last, we tried the min function without arguments (Zero arguments), which returns Infinite.

JavaScript min value in array
We can use the Math.min() function with the spread operator to find the minimum value in an array of elements.
const a = [10, 50, 9, 100, 25, 70, 12];
const m = Math.min(...a);
console.log(m);
9
Alternatively, we can use the array reduce() function to map the min() function to the array elements.
const a = [10, 50, 9, 100, 25, 70, 12];
const m = a.reduce((a, b) => Math.min(a, b));
console.log(m);
9
JavaScript find min value in an array of objects
Similar to the above, we use the Math.min() function to find the minimum value in an array of objects. For this, we must extract the exact object that we want to compare to find the minimum value. For employee age, use against the age object, and for salary, apply the min() function to Salary.
const employees = [
{ name: "John", age: 30, Salary: 100000 },
{ name: "Maddy", age: 39, Salary: 80000 },
{ name: "Charlie", age: 24, Salary: 120000 }
];
const mAge = Math.min(...employees.map(emp => emp.age));
console.log(mAge);
const mSal = Math.min(...employees.map(emp => emp.Salary));
console.log(mSal);
24
80000
How does Math.min() handle null, Undefined, and NaN?
The JavaScript Math.min() function returns the following results if any one of the arguments is null, undefined, or NaN.
- If Null, it returns 0 as the output.
- If it is undefined, it returns NaN as the output.
- If it is NaN (not a number), it returns NaN as the output.
The following program shows the results. Remember, if there is a single argument and its values are either null, undefined, or NaN, the result is the same as the above mentioned (or below) program.
console.log(Math.min(null));
console.log(Math.min(10, null, 20, 40));
console.log(Math.min(undefined));
console.log(Math.min(50, 70, undefined, 40));
console.log(Math.min(NaN));
console.log(Math.min(10, NaN, 30));
0
0
NaN
NaN
NaN
NaN
NOTE: If any of the above-mentioned values (null, undefined, or NaN) are inside an array, the result will be the same.
Related Math functions