Math max()/min() Method

The Math.max() method is used to return the largest of zero or more numbers. The result is “-Infinity” if no arguments are passed and the result is NaN if at least one of the arguments cannot be converted to a number.

The max() is a static method of Math, therefore, it is always used as Math.max(), rather than as a method of a Math object created.

const numberArr = [2, 3, 6, 8, -33, 7, 8, 10, 22, 55, -44, -1, -5];
console.log(Math.max(...numberArr));
// Outcome 55

The Math.min() method is used to return the lowest-valued number passed in the method. The Math.min() method returns NaN if any parameter isn’t a number and can’t be converted into one. The min() is a static method of Math, therefore, it is always used as Math.min(), rather than as a method of a Math object created.

const numberArr = [2, 3, 6, 8, -33, 7, 8, 10, 22, 55, -44, -1, -5];
console.log(Math.min(...numberArr));
// Outcome -44

Last updated