Math.max() function returns the largest of the zero or more numbers given as input parameters.
Math.max(1,10,100); // return 100
//Returns number with highest value.
var x = Math.max(-5, 12, 27);
console.log(x)//27
var arr = [1,2,3];
var max = arr.reduce(function(a, b) {
return Math.max(a, b);
});
// Math.max()
// 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.
// EXAMPLE : 1
let num = Math.max(5,8,100,50);
console.log(num);
// OUTPUT: 100
// EXAMPLE : 2
let num_2 = Math.max(-5,-8,-100,-50);
console.log(num_2);
// OUTPUT: -5
// EXAMPLE : 3
let num_3 = Math.max();
console.log(num_3);
// OUTPUT: -Infinity
// EXAMPLE : 4
let num_4 = Math.max("Haseeb",3,70);
console.log(num_4);
// OUTPUT: NaN (NOT A NUMBER)
var arr = [1,2,3];
var max = Math.max(...arr);