JavaScript Math min() method - JavaScript Tutorial

JavaScript Math min() method

BLUF: This tutorial on JavaScript Math min() method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Math min() method

Understanding JavaScript Math min() method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

The min method in JavaScript's Math object evaluates the provided numerical arguments and returns the smallest value among them.

Syntax

The syntax for the min method is illustrated as follows:

Example

Math.min(num1,num2,...,numN)

Parameter

num1,num2,...,numN - Numbers to be compared..

Return

A minimum value of the given numbers.

JavaScript Math min method example

In this section, we will explore the min function by examining a range of examples.

Example 1

Let’s examine a straightforward example that demonstrates how to output the smallest value among a set of provided numbers.

Example

<script>

document.writeln(Math.min(22,34,12,15)+"<br>"); 

document.writeln(Math.min(-10,-24,-12,-20));

</script>

Output:

Output

12

-24

Example 2

Here’s an illustration of how to display the smallest element from the provided array.

Example

<script>

var arr=[13,15,12,9]

document.writeln(Math.min(...arr)) 

</script>

Output:

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience