JavaScript Arithmetic (Math) Getting maximum and minimum

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

The Math.max() function returns the largest of zero or more numbers.

Math.max(4, 12);   //  12
Math.max(-1, -15); // -1

The Math.min() function returns the smallest of zero or more numbers.

Math.min(4, 12);   //  4
Math.min(-1, -15); // -15

Getting maximum and minimum from an array:

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9],
    max = Math.max.apply(Math, arr),
    min = Math.min.apply(Math, arr);

console.log(max); // Logs: 9
console.log(min); // Logs: 1

ECMAScript 6 spread operator, getting the maximum and minimum of an array:

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9],
    max = Math.max(...arr),
    min = Math.min(...arr);

console.log(max); // Logs: 9
console.log(min); // Logs: 1


Got any JavaScript Question?