🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › min
Math.min() - JavaScript | MDN
console.log(Math.min(2, 3, 1)); // Expected output: 1 console.log(Math.min(-2, -3, -1)); // Expected output: -3 const array = [2, 3, 1]; console.log(Math.min(...array)); // Expected output: 1
🌐
W3Schools
w3schools.com › jsref › jsref_min.asp
JavaScript Math min() Method
The Math.min() method returns the number with the lowest value.
🌐
TutorialsPoint
tutorialspoint.com › javascript › math_min.htm
JavaScript Math.min() Method
<html> <body> <script> let number = Math.min(5, 15, 25, 55, 100); document.write("lowest number: ", number); </script> </body> </html> As we can see the output, the lowest number will be "5". In this example, we are passing the array as an argument ...
🌐
Programiz
programiz.com › javascript › library › math › min
JavaScript Math min()
// min() with a spread operator let minNum = Math.min(...numbers); console.log(minNum); // Output: 1 · In the above example, we have created an array named numbers.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-math-min-method
JavaScript Math min() Method - GeeksforGeeks
July 15, 2024 - The JavaScript Math min( ) Method is used to return the lowest-valued number passed in the method. The Math.min() method returns NaN if any parameter isn't a number and can't be converted into one.
🌐
TechOnTheNet
techonthenet.com › js › math_min.php
JavaScript: Math min() function
In this example, the first output to the console log returned 5 which is the smallest of the values 5 and 10. The second output to the console log returned 20 which is the smallest of the values 60, 40 and 20. The third output to the console log returned -12 which is the smallest of the values ...
🌐
Scaler
scaler.com › home › topics › math min() javascript function
Math min() JavaScript Function - Scaler Topics
May 4, 2023 - There will be multiple instances when we have to find out the minimum of two or more numbers (any type). In Javascript programming, we can use the inbuilt Math.min() function to return the smallest number in a set of numbers (there can be
🌐
LaunchCode
education.launchcode.org › intro-to-professional-web-dev › appendices › math-method-examples › max-and-min-examples.html
Math.max and Math.min Examples — Introduction to Professional Web Development in JavaScript documentation
Math Method Examples · Math.max and Math.min Examples · The general syntax for this method is: Math.max(x, y, z, ...) This method finds and returns the largest value from a set of numbers (x, y, z, ...). To find the maximum value in an array, see below. Example · console.log(Math.max(2, ...
🌐
Math.js
mathjs.org › docs › reference › functions › min.html
math.js | an extensive math library for JavaScript and Node.js
Examples · Compute the minimum value of a matrix or a list of values. In case of a multidimensional array, the minimum of the flattened array will be calculated. When dim is provided, the minimum over the selected dimension will be calculated. Parameter dim is zero-based. math.min(a, b, c, ...
Find elsewhere
🌐
Reality Ripple
udn.realityripple.com › docs › Web › JavaScript › Reference › Global_Objects › Math › min
Math.min() - JavaScript
This finds the min of x and y and assigns it to z: ... Math.min() is often used to clip a value so that it is always less than or equal to a boundary.
🌐
Reintech
reintech.io › blog › tutorial-applying-math-min-method
Applying the Math.min() Method | Reintech media
February 22, 2023 - Choose Math.min() for clarity with small datasets, reduce() for large arrays, and manual iteration when you need additional processing during comparison. For teams seeking experienced developers who write efficient, maintainable JavaScript code, Reintech connects you with vetted JavaScript developers who understand these performance considerations and best practices.
🌐
W3Resource
w3resource.com › javascript › object-property-method › math-min.php
JavaScript min() Method : Math Object - w3resource
<![CDATA[ document.write(Math.min(25,15) + "<br />"); document.write(Math.min(-11,5) + "<br />"); document.write(Math.min(-25,-20) + "<br />"); x=45.65 y=45.66 document.write(Math.min(x,y) + "<br />"); document.write(Math.min(8.65,9.70)); //]]> ...
🌐
W3Schools
w3schools.com › js › js_math.asp
JavaScript Math Object
Math.min(0, 150, 30, 20, -8, -200); Try it Yourself »
Top answer
1 of 7
15

Here is the Math.max code in Chrome V8 engine.

function MathMax(arg1, arg2) {  // length == 2
  var length = %_ArgumentsLength();
  if (length == 2) {
    arg1 = TO_NUMBER(arg1);
    arg2 = TO_NUMBER(arg2);
    if (arg2 > arg1) return arg2;
    if (arg1 > arg2) return arg1;
    if (arg1 == arg2) {
      // Make sure -0 is considered less than +0.
      return (arg1 === 0 && %_IsMinusZero(arg1)) ? arg2 : arg1;
    }
    // All comparisons failed, one of the arguments must be NaN.
    return NaN;
  }
  var r = -INFINITY;
  for (var i = 0; i < length; i++) {
    var n = %_Arguments(i);
    n = TO_NUMBER(n);
    // Make sure +0 is considered greater than -0.
    if (NUMBER_IS_NAN(n) || n > r || (r === 0 && n === 0 && %_IsMinusZero(r))) {
      r = n;
    }
  }
  return r;
}

Here is the repository.

2 of 7
7

Below is how to implement the functions if Math.min() and Math.max() did not exist.

Functions have an arguments object, which you can iterate through to get its values.

It's important to note that Math.min() with no arguments returns Infinity, and Math.max() with no arguments returns -Infinity.

function min() {
  var result= Infinity;
  for(var i in arguments) {
    if(arguments[i] < result) {
      result = arguments[i];
    }
  }
  return result;
}

function max() {
  var result= -Infinity;
  for(var i in arguments) {
    if(arguments[i] > result) {
      result = arguments[i];
    }
  }
  return result;
}

//Tests
console.log(min(5,3,-2,4,14));       //-2
console.log(Math.min(5,3,-2,4,14));  //-2

console.log(max(5,3,-2,4,14));       //14
console.log(Math.max(5,3,-2,4,14));  //14

console.log(min());                  //Infinity
console.log(Math.min());             //Infinity

console.log(max());                  //-Infinity
console.log(Math.max());             //-Infinity

🌐
GitHub
github.com › mdn › content › blob › main › files › en-us › web › javascript › reference › global_objects › math › min › index.md
content/files/en-us/web/javascript/reference/global_objects/math/min/index.md at main · mdn/content
{{InteractiveExample("JavaScript Demo: Math.min()")}} · ```js interactive-example · console.log(Math.min(2, 3, 1)); // Expected output: 1 · · console.log(Math.min(-2, -3, -1)); // Expected output: -3 · · const array = [2, 3, 1]; · ...
Author   mdn
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Math.min and Math.max methods with JS - JavaScript
May 23, 2019 - I first wrote this code: let numbers = (10, 15, 59, 20); let a = Math.max(numbers); console.log(a); …which display 20 in the console. I’ve noticed that it always returns the last number of the numbers variable.
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › Math › min
JavaScript Math min() - Find Minimum Value | Vultr Docs
November 27, 2024 - By spreading the numbers array, each element is passed as a separate argument to Math.min(), which then returns -3 as the smallest value.
🌐
CoreUI
coreui.io › answers › how-to-find-the-minimum-value-in-an-array-in-javascript
How to find the minimum value in an array in JavaScript · CoreUI
September 21, 2025 - Use Math.min() with the spread operator to find the smallest value in an array. const numbers = [3, 7, 2, 9, 1, 5] const minimum = Math.min(...numbers) // Result: 1 · The Math.min() function finds the smallest of the provided arguments, and ...
🌐
Dustin John Pfister
dustinpfister.github.io › 2020 › 01 › 22 › js-math-max-min
Math max and min methods in javaScript | Dustin John Pfister at github pages
November 21, 2021 - So if I give the Math min method the numbers 3, 0, and -7 as arguments then the number -7 is what will be returned. Although this simple example works out okay for what it is, when it comes to any kind of real code example such code examples ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math
Math - JavaScript | MDN
In JavaScript, we can do this with the following: js · 50 * Math.tan(degToRad(60)); We use our degToRad() function to convert 60 degrees to radians, as Math.tan() expects an input value in radians. This can be achieved with a combination of Math.random() and Math.floor(): js · function ...