JavaScript Math.min(): Find the Minimum Number

Last reviewed: by
JavaScript Math.min(): Find the Minimum Number

JavaScript Math.min() returns the smallest number from the values you pass to it. Searches like math min, js math min, javascript math min, math.min javascript, and javascript min all point to this method.

Tested On: The examples were tested with Node.js v20.18.1 on a Linux system. The same Math.min() behavior works in modern browsers and JavaScript runtimes.


Math.min Syntax

Number line illustrating Math.min Math.max and a clamp pattern

javascript
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

javascript
console.log(Math.min(10, 25));

Output:

text
10

Method 2: Find Minimum of Multiple Numbers

javascript
console.log(Math.min(12, 3, 4, 5, 67, 321, 121212));

Output:

text
3

Method 3: Find Minimum Value in an Array

Use spread syntax to pass array values as separate arguments.

javascript
const numbers = [3, 9, 2, 14];

console.log(Math.min(...numbers));

Output:

text
2

Method 4: Handle Empty Input and NaN

Calling Math.min() with no arguments returns Infinity.

javascript
console.log(Math.min());

Output:

text
Infinity

If any argument is NaN, the result is NaN.

javascript
console.log(Math.min(1, NaN, 3));

Output:

text
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

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.


Official Documentation

Olorunfemi Akinlua

Boasting over five years of experience in JavaScript, specializing in technical content writing and UX design. With a keen focus on programming languages, he crafts compelling content and designs user-friendly interfaces to enhance digital …

  • JavaScript
  • Web Design