🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › max
Math.max() - JavaScript | MDN
The Math.max() static method returns the largest of the numbers given as input parameters, or -Infinity if there are no parameters.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Using Math.max to find number - JavaScript - The freeCodeCamp Forum
October 2, 2025 - function nextId(ids){ let max = Math.max(ids.join()); console.log(max) } nextId([0,1,2,3,5]); nextId([0,1,2,3,4,5,6,7,8,9,10]); nextId([1,2,0,2,3,5]); ``` Hello:) Can someone tell me pls, why as a result I get Na…
🌐
freeCodeCamp
forum.freecodecamp.org › guide
JavaScript Math.max() Explained with Examples
September 8, 2019 - Math Max Math.max() is a function that returns the largest value from a list of numeric values passed as parameters. If a non-numeric value is passed as a parameter, Math.max() will return NaN .
🌐
W3Schools
w3schools.com › jsref › jsref_max.asp
JavaScript Math max() Method
The Math.max() method returns the number with the highest value.
🌐
MDN
mdn2.netlify.app › en-us › docs › web › javascript › reference › global_objects › math › max
Math.max() - JavaScript | MDN
March 27, 2022 - The Math.max() function returns the largest of the zero or more numbers given as input parameters, or NaN if any parameter isn't a number and can't be converted into one.
🌐
Reality Ripple
udn.realityripple.com › docs › Web › JavaScript › Reference › Global_Objects › Math › max
Math.max() - JavaScript
The Math.max() function returns the largest of the zero or more numbers given as input parameters.
Find elsewhere
🌐
Math.js
mathjs.org › docs › reference › functions › max.html
math.js | an extensive math library for JavaScript and Node.js
math.max(2, 1, 4, 3) // returns 4 math.max([2, 1, 4, 3]) // returns 4 // maximum over a specified dimension (zero-based) math.max([[2, 5], [4, 3], [1, 7]], 0) // returns [4, 7] math.max([[2, 5], [4, 3], [1, 7]], 1) // returns [5, 4, 7] math.max(2.7, 7.1, -4.5, 2.0, 4.1) // returns 7.1 math.min(2.7, 7.1, -4.5, 2.0, 4.1) // returns -4.5
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › MAX_VALUE
Number.MAX_VALUE - JavaScript | MDN
October 22, 2025 - The Number.MAX_VALUE static data property represents the maximum numeric value representable in JavaScript.
🌐
Anthropic
anthropic.com › news › claude-sonnet-4-5
Introducing Claude Sonnet 4.5
We've added a new context editing feature and memory tool to the Claude API that lets agents run even longer and handle even greater complexity. In the Claude apps, we've brought code execution and file creation (spreadsheets, slides, and documents) directly into the conversation. And we've made the Claude for Chrome extension available to Max users who joined the waitlist last month.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › min
Math.min() - JavaScript | MDN
July 20, 2025 - The Math.min() static method returns the smallest of the numbers given as input parameters, or Infinity if there are no parameters.
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

🌐
Hacker News
news.ycombinator.com › item
Show HN: PureBee – A software-defined GPU running Llama 3.2 1B at 3.6 tok/SEC | Hacker News
2 weeks ago - PureBee is a complete GPU defined as a software specification — Memory, Engine, Instruction Set, Runtime. It runs Llama 3.2 1B inference at 3.6 tok/sec on a single CPU core. The model answers questions correctly · What makes it different from llama.cpp or WebLLM:
🌐
Medium
medium.com › @aniksarkar0177 › what-is-math-max-in-javascript-0999bf68923d
What is Math.max in JavaScript? - Aniksarkar - Medium
October 4, 2023 - In JavaScript, Math.max() is a built-in Math object function used to find the largest value among a set of numbers or elements. You can…
🌐
Droidscript
droidscript.org › javascript › Global_Objects › Math › max.html
Math.max
The Math.max() function returns the largest of zero or more numbers.
🌐
Reading Eggs
readingeggs.com
Learning to Read for Kids | Learn to Read with Phonics | Free Trial – Reading Eggs
Reading Eggs is the online reading program that helps children learn to read. Hundreds of online reading lessons, phonics games and books for ages 2–13. Start your free trial!
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-math-max-method
JavaScript Math max() Method - GeeksforGeeks
September 30, 2024 - The Math.max() method in JavaScript returns the largest value from a set of zero or more numbers.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › javascript tutorial › javascript max
JavaScript Math max() Method [Function & Examples]
April 18, 2023 - Javascript max uses the Math.max to find out the maximum number among the list of the numeric values that are supplied to the function as its parameters. This method helps to retrieve the maximum numeric value.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › array › min and max value of an array
Min and max value of a JavaScript array - 30 seconds of code
December 30, 2023 - You can simply use Math.min() or Math.max() combined with the spread operator (...), as both functions accept any number of arguments. const nums = [2, 4, 6, 8, 1, 3, 5, 7]; Math.max(...nums); // 8 Math.min(...nums); // 1