In JS Math.max() < Math.min() is true
max() and min() are static methods of Math, you always use it as Math.max(), Math.min()
The number arguments that min and max methods can take are zero or more
Math.max([value1[, value2[, ...]]]) Math.min([value1[, value2[, ...]]])
All is well in the JS land if you give 1 or more parameters for both min and max methods. The tricky part is if you do not provide any parameter to these methods. Now why wouldn’t you provide any parameters to max/min methods, that’s altogether a different discussion. However, because the api allows the programmer to provide zero or more parameters, the result of such operation is well documented.
Math.max() gives -Infinity.
Math.min() gives Infinity.
This makes perfect sense, because if you are just providing one parameter to math and min methods the result is always the same as the input.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
Math.max() -Infinity Math.min() Infinity Math.max() > Math.min() false Math.max(1,3,2) 3 Math.min(1,3,2) 1 Math.max(2) 2 Math.min(2) 2 Math.max(3) > Math.min(1) true Math.max(1) > Math.min(3) false
One thought on “In JS Math.max() < Math.min() is true”
why it is returning -infinity and +infinity ? Any algorithm level explanation is really helpful!
Is it mean Math.max() lower boundary is fixed i.e, -Infinity not upper boundary? If we pass any value to the max() method it’s not lower than lower boundary value i.e, -Infinity.
Is it mean Math.min() upper boundary is fixed i.e, +infinity not lower boundary? If we pass any value to the min() method it’s not upper than upper boundary value i.e, +Infinity.