🌐
W3Schools
w3schools.com › jsref › jsref_min.asp
JavaScript Math min() Method
The Math.min() method returns the number with the lowest value.
🌐
W3Schools
w3schools.com › js › tryit.asp
JavaScript Math.min()
The W3Schools online code editor allows you to edit code and view the result in your browser
Discussions

How do Javascript Math.max and Math.min actually work? - Stack Overflow
I am really curious how these functions actually work? I know there are a lot of questions about how to use these, I already know how to use them, but I couldn't find anywhere how to actually go ab... More on stackoverflow.com
🌐 stackoverflow.com
Math.min and Math.max methods with JS
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. Then, i wrote this (I’ve found it on W3S and modify it a bit): function ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
0
May 23, 2019
Find the min/max element of an array in JavaScript - Stack Overflow
2 I have a low temperature array in javascript and I need to get the lowest temp so I used the min.math function More on stackoverflow.com
🌐 stackoverflow.com
Why don't Math.max and Math.min accept arrays? Why are they n-arity functions?
or ES6+ version Math.min(...myNums) More on reddit.com
🌐 r/javascript
33
41
February 13, 2017
🌐
W3Schools
w3schools.com › js › js_math.asp
JavaScript Math Object
Math.min(0, 150, 30, 20, -8, -200); Try it Yourself »
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › min
Math.min() - JavaScript - MDN Web Docs
July 20, 2025 - 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.
🌐
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 to this method − · <html> <body> <script> let Array = [10, 20, 30, 40, 50, 60, 90]; let MinNum = Math.min(...Array); document.write("Lowest number: ", MinNum); </script> </body> </html>
🌐
TechOnTheNet
techonthenet.com › js › math_min.php
JavaScript: Math min() function
This JavaScript tutorial explains how to use the math function called min() with syntax and examples. In JavaScript, min() is a function that is used to return the smallest value from the numbers provided as parameters.
🌐
Programiz
programiz.com › javascript › library › math › min
JavaScript Math min()
The JavaScript Math.min() method finds the minimum value among the specified values and returns it. In this tutorial, you will learn about the min() method with the help of examples
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math
Math - JavaScript - MDN Web Docs
This can be achieved with a combination of Math.random() and Math.floor(): ... function random(min, max) { const num = Math.floor(Math.random() * (max - min + 1)) + min; return num; } random(1, 10);
Find elsewhere
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

🌐
Educative
educative.io › answers › what-are-mathmin-and-mathmax-in-javascript
What are Math.min() and Math.max() in JavaScript?
This is because when we compare any number to infinity, infinity will always be the higher value; so, the number becomes the min value. console.log("Calling Math.min with no arguments ");
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-math-min-method
JavaScript Math min() Method | GeeksforGeeks
July 15, 2024 - We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript. ... The Math.E is a property in JavaScript that simply returns the value of Euler's Number, which is nothing but just has a base of the natural logarithm.
🌐
W3Schools
w3schools.com › jsref › jsref_min_value.asp
JavaScript MIN_VALUE Property
Number.MIN_VALUE returns the smallest number possible in JavaScript.
🌐
Math.js
mathjs.org › docs › reference › functions › min.html
math.js | an extensive math library for JavaScript and Node.js
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, ...) math.min(A) math.min(A, dimension)
🌐
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. Then, i wrote this (I’ve found it on W3S and modify it a bit): function myFunction() { var a = Math.min(5, 10); var b = Math.min(0, 150, 30, 20, 38); var c = Math.min(-5, 10); var d = Math.min(-5, -10); var e = Math.min(1.5, 2.5); console.log(a + " " + b + " " + ...
🌐
Reintech
reintech.io › blog › tutorial-applying-math-min-method
Applying the Math.min() Method | Reintech media
January 13, 2026 - Learn how to use the Math.min() method in JavaScript with this comprehensive tutorial.
🌐
W3Schools
w3schools.com › jsref › jsref_obj_math.asp
JavaScript Math Reference
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
🌐
Scaler
scaler.com › home › topics › math min() javascript function
Math min() JavaScript Function - Scaler Topics
May 4, 2023 - Learn about Math min() javascript function. Scaler Topics explains the syntax, parameters, and return values along with examples. Click here to know more.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › find-the-min-max-element-of-an-array-using-javascript
Min and Max of an Array in JavaScript - GeeksforGeeks
let Arr = [50, 60, 20, 10, 40]; let minVal = Math.min(...Arr); let maxVal = Math.max(...Arr); console.log("Min Elem is:" + minVal); console.log("Max Elem is:" + maxVal); ... Math.min(...Arr) and Math.max(...Arr) find the smallest (10) and largest ...
Published   August 2, 2025