When passing values to the Math.max or Math.min function in JavaScript, they return the highest and lowest values from the input respectively.
However, if a piece of data that is undefined is entered, e.g.
Math.max(5,10,undefined);
The result returned is NaN. Is there a simply way to fix this using JS/jQuery?
I assume the
undefinedis actually some variable.You can substitute
-Infinityfor anyNaNvalue to ensure a number.Same concept can be used on
Math.min, but withInfinity: