Math.min()
Math.min([value1[, value2[, ...]]]) Returns:
number · Added in vES1 · Updated March 13, 2026 · Math math min minimum numbers clamping
Math.min() returns the lowest value from zero or more numbers. It’s the counterpart to Math.max() and essential for clamping values, finding bounds, and enforcing minimum thresholds in your code.
Syntax
Math.min()
Math.min(value1)
Math.min(value1, value2)
Math.min(value1, value2, ..., valueN)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
value1, ..., valueN | number | — | Zero or more numbers to compare |
Return Value
The smallest of the given numbers. Returns Infinity when called with no arguments.
Examples
Basic usage with numbers
Math.min(5, 3, 8, 1);
// 1
Math.min(42);
// 42
Math.min(-10, -5, -20);
// -20
Math.min(100, 50);
// 50
Empty argument list returns Infinity
A unique behavior that serves as the identity element for Math.min():
Math.min();
// Infinity
// This matters when reducing arrays:
const values = [Global_Objects::eval];
values.reduce((a, b) => Math.min(a, b), Infinity);
// Infinity (for empty array)
Using the spread operator with arrays
Apply Math.min() to array contents using the spread operator:
const numbers = [5, 2, 8, 1, 9, 3];
Math.min(...numbers);
// 1
Math.max(...numbers);
// 9
// Compare without spread (doesn't work):
Math.min([5, 2, 8]);
// NaN - arrays are not unpacked automatically
Handling non-numeric values
Math.min() coerces strings and null, but returns NaN for undefined, objects, and symbols:
// Coerced to numbers
Math.min('5', '2', '8');
// 2
Math.min(null, 0, -5);
// -5 (null coerces to 0)
Math.min(1, undefined);
// NaN (undefined cannot coerce)
// Objects and arrays return NaN
Math.min({}, [Global_Objects::eval]);
// NaN
// Practical: filter valid numbers first
const mixed = [5, '2', null, undefined, 8];
const valid = mixed.filter(n => typeof n === 'number' && !isNaN(n));
Math.min(...valid);
// 2
Common use case: Clamping a value
The classic pattern for constraining a number within bounds:
function clamp(value, min, max) {
return Math.min(Math.max(value, min), max);
}
// Prevent value from going below minimum
clamp(5, 10, 100);
// 10
// Prevent value from going above maximum
clamp(200, 10, 100);
// 100
// Value within range stays unchanged
clamp(50, 10, 100);
// 50
// Real-world: ensure scroll position stays in bounds
const scrollY = Math.min(Math.max(currentScroll, 0), maxScroll);
Math.min() vs Math.max()
They mirror each other but have one key difference:
// Symmetric behavior
Math.min(1, 2, 3); // 1
Math.max(1, 2, 3); // 3
// Empty arguments: inverse identities
Math.min(); // Infinity
Math.max(); // -Infinity
Edge Cases
Math.min(NaN, 1, 2);
// NaN - any NaN input propagates
Math.min(Infinity, 100);
// 100
Math.min(-Infinity, -100);
// -Infinity
Math.min(0, -0);
// -0 (negative zero is smaller)
Performance Tip
For finding minima in large arrays, prefer the spread operator over apply():
// Modern and clean
Math.min(...arr);
// Older alternative (works but less readable)
Math.min.apply(null, arr);
Both perform similarly on modern engines—choose readability.
See Also
- math::max — Return the largest number
- number::isFinite — Check if value is a finite number