Of course it would, because the start number should be Infinity for Math.min. All number that are lower than positive infinity should be the smallest from a list, if there are no smaller.

And for Math.max it's the same; all numbers that are larger than negative infinity should be the biggest if there are no bigger.

So for your first example:

Math.min(5) where 5 is smaller than positive infinity (Infinity) it will return 5.

Update

Calling Math.min() and Math.max with an array parameter may not work on every platform. You should do the following instead:

Math.min.apply(null, [ 1, 2, 3, 4 , 5 ]);

Where the first parameter is the scope argument. Because Math.min() and Math.max() are "static" functions, we should set the scope argument to null.

Answer from KARASZI István on Stack Overflow
Top answer
1 of 10
50

Of course it would, because the start number should be Infinity for Math.min. All number that are lower than positive infinity should be the smallest from a list, if there are no smaller.

And for Math.max it's the same; all numbers that are larger than negative infinity should be the biggest if there are no bigger.

So for your first example:

Math.min(5) where 5 is smaller than positive infinity (Infinity) it will return 5.

Update

Calling Math.min() and Math.max with an array parameter may not work on every platform. You should do the following instead:

Math.min.apply(null, [ 1, 2, 3, 4 , 5 ]);

Where the first parameter is the scope argument. Because Math.min() and Math.max() are "static" functions, we should set the scope argument to null.

2 of 10
39

It's tricky, but important, to decide correctly what aggregate functions should do when passed the empty set.

Sometimes it's 'intuitively obvious': What is the SUM of no elements? Zero, I'm sure everyone would readily say.

Sometimes it's less so: What is the PRODUCT of no elements? Those with some mathematical training will quickly say "one", but this is not at all obvious.

Then you get to MIN and MAX and wow! How did we get those infinities?


One way to decide what an aggregate function should do here is consider what behaviours we want to remain consistent, even with empty sets. For example, suppose we have these non-empty sets:

A = { 1, 2, 3 } 
B = { 4, 5 }

Now, it's true here, and indeed for any non-empty sets, that

SUM(A ∪ B) = SUM({SUM(A), SUM(B)})
15 = 6 + 9

PRODUCT(A ∪ B) = PRODUCT({ PRODUCT(A), PRODUCT(B) })
120 = 6 * 20

MIN(A ∪ B) = MIN({ MIN(A), MIN(B) })
1 = MIN(1, 4)

Wouldn't it be nice, say the mathematicians, if these properties remain true even when one or both of the sets are empty? It surely would.

And it's maintaining this behaviour that decides what value we assign to SOME_AGGREGATE_FUNCTION(∅) :

In order for

SUM(A ∪ B) = SUM({ SUM(A), SUM(B) })

to remain true when A is empty and B is not, we must have SUM(∅) = 0

In order for

PRODUCT(A ∪ B) = PRODUCT({ PRODUCT(A), PRODUCT(B) })

to remain true when A is empty and B is not, we must have PRODUCT(∅) = 1

And finally:

In order for

MIN(A ∪ B) = MIN({ MIN(A), MIN(B) })

to remain true when A is empty and B is not, we need MIN(∅) to be a value which is guaranteed to be greater than any possible value in B, so that it doesn't 'interfere with' the result of MIN(B). And we get our answer: MIN(∅) = +∞

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › min
Math.min() - JavaScript - MDN Web Docs
The Math.min() static method returns the smallest of the numbers given as input parameters, or Infinity if there are no parameters.
Discussions

javascript - Applying Math.min() to an empty list produces -Infinity instead of 0 - Stack Overflow
I have developed a code in which adds values and at the end subtracts the smallest value based on the items you select in a form. The code works fine however the problem occurs when you unselect al... More on stackoverflow.com
🌐 stackoverflow.com
April 16, 2013
Why is Math.max() less than Math.min()?
I got this far in the article: > Math.max() Math.max() -Infinity > Math.min() Infinity So really it's just saying that negative infinity is less than positive infinity, which is true. And it makes sense that those are the 'default' values you get when you don't supply any arguments, as they're basically the respective identities for the two functions. Just like 0 is the additive identity and 1 is the multiplicative, -Infinity is the "maximizing" identity. For any number X, Math.max(-Infinity, X) is X. More on reddit.com
🌐 r/javascript
28
98
February 24, 2015
Negative Infinity
How are you defining infinity and arithmetic on it? There are different notions that lead to different answers. More on reddit.com
🌐 r/mathematics
59
0
September 13, 2023
Interesting........Any explanations why Math.max return negative infinity?
The maximum of zero arguments should be less than* the maximum of one or more than any other set of valid arguments, thus it is the lowest possible value; negative infinity. Min is the opposite of this logic. i.e. Math.max(...[]) < Math.max(...[1]); // true and Math.max(...[]) < Math.max(...[Number.MIN_SAFE_INTEGER]); //true makes sense. * I suppose you could less than or equal to if you include -Infinity itself More on reddit.com
🌐 r/learnjavascript
35
86
July 18, 2021
🌐
DEV Community
dev.to › dance2die › math-min-returns-infinity-1bi6
Math.min returns Infinity? - DEV Community
June 23, 2019 - Any value other than Infinity itself (Infinity === Infinity is true) should be the minimum, and as 3 is smaller than Infinity, 3 is returned by Math.min.
🌐
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 ");
🌐
Dmitri Pavlutin
dmitripavlutin.com › infinity-in-javascript
Infinity in JavaScript - Dmitri Pavlutin
October 2, 2022 - Some functions of Math namespace in JavaScript can return infinite numbers. ... Math.max() when invoked without arguments returns -Infinity, and Math.min() correspondingly Infinity.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Infinity
Infinity - JavaScript - MDN Web Docs
console.log(Infinity); /* Infinity */ console.log(Infinity + 1); /* Infinity */ console.log(10 ** 1000); /* Infinity */ console.log(Math.log(0)); /* -Infinity */ console.log(1 / Infinity); /* 0 */ console.log(1 / 0); /* Infinity */
Find elsewhere
🌐
Medium
medium.com › @rohitkuwar › understanding-infinity-in-javascript-a-guide-for-developers-f3b33570fb14
Understanding Infinity in JavaScript: A Guide for Developers | by Rohit Kuwar | Medium
September 10, 2025 - In this example, Infinity serves as a placeholder for comparison. Any number in the array will be less than Infinity, so it guarantees that the first comparison will update min to the first number in the array.
🌐
Scaler
scaler.com › home › topics › what is infinity in javascript?
What is Infinity in JavaScript? - Scaler Topics
December 20, 2022 - If we try to use a number bigger than that then we get Infinity ... Math. max() and Math. min() are the two Math methods when invoked without arguments resulting in -Infinity and Infinity respectively.
🌐
DEV Community
dev.to › salyadav › little-shenanigans-of-javascript-2-2dkb
Little Shenanigans of JavaScript - Max is Negative Infinity? WHAT! - DEV Community
July 18, 2020 - Although this feels very counterintuitive to have min() as +Infinity and max() as negative, I find an explanation very convincing... Let's take Math.min(). We use it to find the minimum number from a set. When you call it with no parameters, ...
🌐
TechOnTheNet
techonthenet.com › js › math_min.php
JavaScript: Math min() function
In JavaScript, the syntax for the ... value. The min() function returns the smallest value from the numbers provided. If no parameters are provided, the min() function will return Infinity....
🌐
Mimo
mimo.org › glossary › javascript › infinity-property
JavaScript Infinity Property: Syntax, Usage, and Examples
JavaScript doesn’t throw an error when dividing by zero. Instead, it returns Infinity or -Infinity: ... Use this behavior to identify when computations might be invalid or need special handling. In simulations or algorithms, you might need to define a maximum boundary: ... let minDistance ...
🌐
Scaler
scaler.com › home › topics › math min() javascript function
Math min() JavaScript Function - Scaler Topics
May 4, 2023 - The min() function is a static method of the in-built Math object. ... InfinityInfinity if no value is passed to it and NaN (Not a Number) if a non-numerical value is passed to the function among other values.
🌐
Charlieharvey
charlieharvey.org.uk › page › why_math_max_is_less_than_math_min
Why is Math.max() less than Math.min()? -- Charlie Harvey
March 2, 2015 - If it were Infinity, then max would always return Infinity. If it were 0 then, if our list of numbers had only negative numbers in it, max would return 0. [ 2 ] For the sake of completeness, we can define min similarly.> min = function(identity, ...
🌐
W3Schools
w3schools.com › jsref › jsref_min.asp
JavaScript Math min() Method
The Math.min() method returns the number with the lowest value.
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript tutorial › javascript infinity
JavaScript Infinity
October 6, 2023 - The following Math.min() method ... console.log(max); // InfinityCode language: JavaScript (javascript) The Infinity represents an infinite number....
🌐
Medium
medium.com › @vdsnini › math-max-is-less-than-math-min-in-javascript-80f678c80e3a
Math.max() is Less than Math.min() in JavaScript | by Beenish Khan | Medium
July 4, 2024 - Since -Infinity is indeed less than Infinity, the statement Math.max() < Math.min() evaluates to true when no arguments are passed to these functions.
🌐
Dmitri Pavlutin
dmitripavlutin.com › javascript-math-max-infinity
Why Math.max() Without Arguments Returns -Infinity
Making a parallel between max and addition, -Infinity for max is the same as 0 for addition. The same behavior happens with Math.min() — it returns Infinity when called without arguments.
🌐
javascriptroom
javascriptroom.com › blog › why-does-math-min-return-positive-infinity-while-math-max-returns-negative-infinity
Why Does JavaScript's Math.min() Return Infinity and Math.max() Return -Infinity When Called With No Parameters?
This aligns with the identity element logic: combining an empty set of numbers with min or max operations returns their respective identity elements (Infinity for min, -Infinity for max).
🌐
Reddit
reddit.com › r/javascript › why is math.max() less than math.min()?
r/javascript on Reddit: Why is Math.max() less than Math.min()?
February 24, 2015 - Just like 0 is the additive identity and 1 is the multiplicative, -Infinity is the "maximizing" identity. For any number X, Math.max(-Infinity, X) is X. ... Weird. I can see how that would be confusing in that case. It would never even occur to me to think of it like that, but I've used Math.min and Math.max reasonably often.