Let's begin with finding the largest number value:
const highest = Math.max(1, 77, 34); console.log(highest); // 77
Here we use the max() method, pass in some values, and the highest value is stored as a constant.
You can now probably guess how min() works now too:
const lowest = Math.min(1, 77, 34); console.log(lowest); // 1
Both of these methods can also be used with negative numbers too.
What about arrays of numbers? The first thought may be to create an array, and pass it into min/max():
const numbers = [1, 77, 34]; const highest = Math.max(numbers); console.log(highest); // NaN
This will result in NaN because we are passing in an array, rather than the actual numbers contained in it.
const numbers = [1, 77, 34]; const highest = Math.max(...numbers); console.log(highest); // 77
And again this can also be used with min() too, resulting in the lowest number.