How to use Math.min() Function In Javascript

You can utilize the `Math.min()` function, which directly returns the smallest among the provided numbers, making it a concise and efficient approach to find the smallest among three numbers in JavaScript.

Example: To demonstrate using the Math.min() to find the minimum value among the three numbers num1, num2, and num3, returning the smallest number.

Javascript




function findSmallest(num1, num2, num3) {
    return Math.min(num1, num2, num3);
}
 
// Example usage
const num1 = 10;
const num2 = 5;
const num3 = 12;
 
const smallest = findSmallest(num1, num2, num3);
console.log("The smallest number is:", smallest);


Output

The smallest number is: 5

JavaScript Program to Find the Smallest Among Three Numbers

In JavaScript, finding the smallest among three numbers is a common task in programming. There are multiple approaches to achieving this, each with its advantages and use cases.

There are several approaches in JavaScript to find the smallest among three numbers which are as follows:

Table of Content

  • Using Conditional Statements
  • Using Math.min() Function
  • Using sort method

Similar Reads

Using Conditional Statements

The simplest approach is to use conditional statements (if, else if, else) to compare the numbers and find the smallest one....

Using Math.min() Function

...

Using sort method

You can utilize the `Math.min()` function, which directly returns the smallest among the provided numbers, making it a concise and efficient approach to find the smallest among three numbers in JavaScript....

Contact Us