Get the Max of two Numbers using JavaScript

 

Use the Math.max() function to get the max of n numbers

 

The function takes zero or more numbers as parameters and returns the largest number. 

 

console.log(Math.max(5, 10)); // 10
console.log(Math.max(0, 20)); // 20
console.log(Math.max(-10, 10)); // 10
console.log(Math.max(-10, -15)); // -10
console.log(Math.max('5', '15')); // 15
console.log(Math.max('zero', 'five')); // NaN

console.log(Math.max(1, 3, 5, 7)); // 7

Tags:

Share:

Related posts