JavaScript Math.min() Method

Definition
Math.min(...values) returns the smallest of the numbers you give it. Pass any number of values, such as Math.min(3, 9, 5), which returns 3.
Math is built into JavaScript. Call the method directly. It is not a constructor, so never write new Math().
Syntax
Call Math.min() like this. Start with this line.
Math.min(value1, value2, /* …, */ valueN)
| Call | What it does |
|---|
Math.min(value1, value2, ...) | Returns the smallest of the given numbers. |
Math.min() | With no arguments, returns Infinity. |
Built into JavaScript. Call Math.min() on the Math object — no import required.
Library declarations
Math.min(value1, value2, /* …, */ valueN)
interface Math {
min(...values: number[]): number;
}
Parameters
| Parameter | Description |
|---|
| value1, ..., valueN | Optional. Zero or more numbers to compare. Other values are converted to numbers. |
Return Value
| Return Value | Description |
|---|
| number | The smallest value. Returns Infinity if there are no arguments, and NaN if any argument is NaN or cannot be turned into a number. |
JavaScript Examples
Example 1 — Basic Use
Pass numbers one by one. You get the smallest.
console.log(Math.min(3, 9, 5)); // 3
console.log(Math.min(-1, -5)); // -5
console.log(Math.min(2, "7")); // 2
console.log(Math.min()); // Infinity
How It Works
- Pick the smallest.
3 is smaller than 9 and 5. - Negatives.
-5 is smaller than -1. - Text numbers.
"7" is converted to the number 7, so 2 still wins. - No values.
Math.min() returns Infinity.
Example 2 — Smallest Number in an Array
Use the spread operator ... to pass array items as arguments.
var prices = [19.99, 5.5, 12, 8.25];
console.log(Math.min(...prices)); // 5.5
console.log(Math.min.apply(null, prices)); // 5.5
var cheapest = prices.indexOf(Math.min(...prices));
console.log(cheapest); // 1
How It Works
- Spread.
...prices turns the array into separate values. - apply.
Math.min.apply(null, prices) is the older way and gives the same answer. - Find the position.
indexOf of the min tells you which item is cheapest.
Example 3 — Cap a Value and Watch for NaN
Use Math.min() to stop a value from going above a limit.
var price = 400;
var discount = Math.min(price * 0.2, 50);
console.log(discount); // 50
var small = 100;
console.log(Math.min(small * 0.2, 50)); // 20
console.log(Math.min(20, NaN)); // NaN
console.log(Math.min(5, null)); // 0
How It Works
- Cap.
400 * 0.2 is 80, but the cap is 50, so you get 50. - Under the cap. For
100, the discount is 20, which is below the cap. - NaN trap. One
NaN makes the whole result NaN. - null trap.
null becomes 0, which is the smallest.
Compatibility
Browser & Runtime Support
Math.min() has been part of JavaScript since ES1 and is Baseline Widely available everywhere.
✓ Baseline · ES1
Math.min()
Supported in every browser and Node.js version. No polyfill is needed.
99% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full supportMath.min Excellent
Bottom line: Use Math.min() freely. It works in all browsers and runtimes.
Frequently Asked Questions
Math.min(a, b, c) returns the smallest number from its arguments. Math.min(3, 9, 5) is 3.
Use the spread operator: Math.min(...numbers). The older way is Math.min.apply(null, numbers).
It returns Infinity. This is because every number is smaller than Infinity.
The result is NaN. Remove or fix bad values before you call Math.min().
Use Math.min(value, limit). For example, Math.min(250, 100) is 100, so the value never goes above 100.
Yes. Math.min(5, null) is 0 because null is converted to 0. Filter out null first if you do not want that.
About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful