🌐
WebPlatform
webplatform.github.io › docs › javascript › Math › min
min · WebPlatform Docs
javascript · Math · min · Returns the smaller of a set of numeric expressions. Math.min([ number1 [, number2 [... [, numberN ]]]]) The following code shows how to get the smaller of two expressions. var x = Math.min(107 - 3, 48 * 90); document.write(x); // Output: // 104 ·
🌐
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 - In this section I will be going over a few basic examples of the Math.min, and Math max methods in the Math object of core javaScript. I will also be touching base on any and all other related topics in this basic section before getting into more advanced topics and any and all simple project examples.
🌐
GitHub
github.com › josdejong › mathjs
GitHub - josdejong/mathjs: An extensive math library for JavaScript and Node.js · GitHub
An extensive math library for JavaScript and Node.js - josdejong/mathjs
Author   josdejong
🌐
Math.js
mathjs.org › download.html
math.js | an extensive math library for JavaScript and Node.js
Math.js works on any ES5 compatible ... work on older browsers when using the es5-shim. The source code of math.js is available on GitHub: https://github.com/josdejong/mathjs....
🌐
Reality Ripple
udn.realityripple.com › docs › Web › JavaScript › Reference › Global_Objects › Math › min
Math.min() - JavaScript
The static function Math.min() returns the lowest-valued number passed into it, or NaN if any parameter isn't a number and can't be converted into one. The source for this interactive example is stored in a GitHub repository.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › min
Math.min() - JavaScript | MDN
const x = Math.min(f(foo), boundary); Math.max() can be used in a similar way to clip a value at the other end. Math.max() Was this page helpful to you? Yes · No Learn how to contribute · This page was last modified on Jul 20, 2025 by MDN contributors. View this page on GitHub • Report ...
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

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math
Math - JavaScript | MDN
function random(min, max) { const num = Math.floor(Math.random() * (max - min + 1)) + min; return num; } random(1, 10); Number · Was this page helpful to you? Yes · No Learn how to contribute · This page was last modified on Jul 10, 2025 by MDN contributors. View this page on GitHub • Report a problem with this content
Find elsewhere
🌐
GitHub
github.com › josdejong › mathjs-expression-parser
GitHub - josdejong/mathjs-expression-parser: Just the expression parser of mathjs
The size of mathjs-expression-parser is 30 KiB when minified and gzipped (about a quarter of the size of mathjs).
Starred by 56 users
Forked by 8 users
Languages   JavaScript
🌐
GitHub
github.com › josdejong › mathjs › issues › 192
debugger errors including math.min.js · Issue #192 · josdejong/mathjs
April 8, 2014 - I am using the previous directions of var mathjs=mathjs(); tried var mathjs=require('../index'),math=mathjs(); but this didn't fix things. with your new example in basuc usage examples page, I get the following error: Error: http://j/math.min.js is being assigned a //# sourceMappingURL, but already has one ReferenceError: require is not defined usb-speed.html:337
Published   Jun 21, 2014
🌐
Esdiscuss
esdiscuss.org › topic › math-minmax
Math.minmax
Had a relatively simple idea tonight : https://github.com/Xstoudi/proposal-math-minmax Please take a look, comment and tell me if you're an interested tc39 champion. -------------- next part -------------- An HTML attachment was scrubbed...
🌐
GitHub
github.com › League-of-Foundry-Developers › mathjs-lib
GitHub - League-of-Foundry-Developers/mathjs-lib: The Math.js library packaged for Foundry VTT
The Math.js library packaged for Foundry VTT. Contribute to League-of-Foundry-Developers/mathjs-lib development by creating an account on GitHub.
Forked by 3 users
Languages   JavaScript
🌐
GitHub
github.com › josdejong › mathjs › blob › develop › HISTORY.md
mathjs/HISTORY.md at develop · josdejong/mathjs
Fix #2971: improve typings of statistics functions min, max, mean, median, mode, std, sum, prod, variance. Fixes a regression introduced in v11.8.1. Fix #2972: type definitions of Unit.divide(Unit) have a wrong return type. Fix #2964: issue in function distance when calculate the distance from a point to a line (#2965). Thanks @Kiku-CN. Fix math.format not working correctly for engineering notation when using BigNumbers and for fixed notation with precision: 0 configured (#2956).
Author   josdejong
🌐
W3Schools
w3schools.com › jsref › jsref_min.asp
JavaScript Math min() Method
The Math.min() method returns the number with the lowest value.
🌐
GitHub
github.com › topics › mathjs
mathjs · GitHub Topics
react productivity calculator typescript chartjs web-application unit-conversion scientific-calculator graphing-calculator mathjs financial-calculator tailwindcss vite ... A tiny, safe, fast JavaScript library for decimal arithmetic expressions.
🌐
GitHub
github.com › dzarate999 › Math.min-Alternative
GitHub - dzarate999/Math.min-Alternative: Using functions to mimic the Math.min command.
Using functions to mimic the Math.min command. . Contribute to dzarate999/Math.min-Alternative development by creating an account on GitHub.
Author   dzarate999
🌐
cdnjs
cdnjs.com › home › libraries › mathjs
mathjs - Libraries - cdnjs - The #1 free and open source CDN built to make life easier for developers
Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser and offers an integrated solution to work with numbers, big numbers, complex numbers, units, and matrices. ... You can contribute on GitHub to help make cdnjs sustainable!
🌐
Webdocs
webdocs.dev › en-us › docs › web › javascript › reference › global_objects › math › min
Math.min() - JavaScript | webdocs.dev
const x = Math.min(f(foo), boundary); Math.max() can be used in a similar way to clip a value at the other end. BCD tables only load in the browser · Math.max() Edit the page on GitHub.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › MIN_VALUE
Number.MIN_VALUE - JavaScript | MDN
The following code divides two numeric values. If the result is greater than or equal to MIN_VALUE, the func1 function is called; otherwise, the func2 function is called. ... This page was last modified on Jul 10, 2025 by MDN contributors. View this page on GitHub • Report a problem with ...