JavaScript Math.min() returns the smallest of the numeric arguments you pass in. When the candidates already live in an array, spread them into the call—for example Math.min(...values)—or fall back to reduce if the array might be empty, because Math.min() with no arguments returns Infinity. For the largest value from the same inputs, use JavaScript Math.max().
Environment: Node.js v20.18.2. Each snippet is plain JavaScript; the line after it states the expected console output.
Math.min Syntax
Math.min(value1, value2, ...valueN)It returns the smallest numeric value. If any argument becomes NaN, the result is NaN.
Method 1: Find Minimum of Two Numbers
console.log(Math.min(10, 25));You should see one line logging 10.
Method 2: Find Minimum of Multiple Numbers
console.log(Math.min(12, 3, 4, 5, 67, 321, 121212));You should see one line logging 3.
Method 3: Find Minimum Value in an Array
Use spread syntax to pass array values as separate arguments.
const numbers = [3, 9, 2, 14];
console.log(Math.min(...numbers));You should see one line logging 2.
Method 4: Handle Empty Input and NaN
Calling Math.min() with no arguments returns Infinity.
console.log(Math.min());You should see one line logging Infinity.
If any argument is NaN, the result is NaN.
console.log(Math.min(1, NaN, 3));You should see one line logging NaN.
Common Questions About Math.min
How do I find the minimum number in JavaScript?
Use Math.min(a, b, c) for direct values, or Math.min(...array) for an array.
Why does Math.min return Infinity?
Math.min() returns Infinity when called with no arguments.
Does Math.min work with arrays directly?
No. Use Math.min(...numbers), not Math.min(numbers).
Summary
Math.min mirrors Math.max with Infinity / NaN edge cases—spread arrays when the length is dynamic.
JavaScript Math.min() returns the smallest number from its arguments. Use it for direct numeric values or with spread syntax for arrays. No arguments return Infinity, and any NaN argument makes the result NaN.
