Math.min()

Returns the smallest of the given numbers.

Returns
The smallest number, NaN, or Infinity with no arguments.
On this page

Example

#
JavaScript
const prices = [79, 49, 59]

console.log(Math.min(...prices))
console.log(Math.min(130, 100))
console.log(Math.min())
Console
49
100
Infinity

Definition and usage

#

The Math.min() function works like Math.max(), but returns the smallest of the arguments. Called with no arguments, it returns Infinity.

For arrays you also need the spread syntax: Math.min(...prices).

It’s often used to cap a value from above, for example so a progress bar doesn’t exceed 100%: Math.min(progress, 100).

Syntax

#
Syntax
Math.min(value1, value2, …)

Parameters

#
  • value1…valueN

    numbers

    The values being compared.

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Very large arrays (hundreds of thousands of elements) can exceed a function’s argument limit. Use reduce() instead in that case.
  • Math.min(value, 100) is a simple way to set an upper limit.

Related entries

#

Spotted a mistake or missing an example? Write to us.