JavaScript Math.min()
Syntax & Examples


Math.min() static-method

The Math.min() static method in JavaScript returns the smallest of zero or more numbers. If no arguments are given, the result is Infinity.


Syntax of Math.min()

There are 4 variations for the syntax of Math.min() static-method. They are:

1.
Math.min()

This static-method returns +Infinity, since no arguments are given.

Returns value of type Number.

2.
Math.min(value1)

Parameters

ParameterOptional/RequiredDescription
value1requiredThe first number to compare.

This static-method returns the value of value1.

Returns value of type Number.

3.
Math.min(value1, value2)

Parameters

ParameterOptional/RequiredDescription
value1requiredThe first number to compare.
value2requiredThe second number to compare.

This static-method returns the smallest of value1 and value2.

Returns value of type Number.

4.
Math.min(value1, value2, /* …, */ valueN)

Parameters

ParameterOptional/RequiredDescription
value1requiredThe first number to compare.
value2requiredThe second number to compare.
valueNoptionalAdditional numbers to compare.

This static-method returns the smallest of value1, value2, and additional arguments valueN.

Returns value of type Number.



✐ Examples

1 Using Math.min() with no arguments

In JavaScript, if no arguments are provided to the Math.min() method, it returns Infinity.

For example,

  1. We call the Math.min() method with no arguments.
  2. The result is stored in the variable result.
  3. We log result to the console using the console.log() method.

JavaScript Program

const result = Math.min();
console.log(result);

Output

Infinity

2 Using Math.min() with one argument

In JavaScript, we can use the Math.min() method to find the smallest of one number, which is the number itself.

For example,

  1. We call the Math.min() method with one argument 5.
  2. The result is stored in the variable result.
  3. We log result to the console using the console.log() method.

JavaScript Program

const result = Math.min(5);
console.log(result);

Output

5

3 Using Math.min() with multiple arguments

In JavaScript, we can use the Math.min() method to find the smallest of multiple numbers.

For example,

  1. We call the Math.min() method with arguments 10, 3, 15, and 7.
  2. The result is stored in the variable result.
  3. We log result to the console using the console.log() method.

JavaScript Program

const result = Math.min(10, 3, 15, 7);
console.log(result);

Output

3

Summary

In this JavaScript tutorial, we learned about min() static-method of Math: the syntax and few working examples with output and detailed explanation for each example.