I am reading this article about Math.max()
and just wondering why the example given uses the spread syntax?
Can’t it be written simply as Math.max(array1)
?
const array1 = [1, 3, 2];
console.log(Math.max(...array1));
// expected output: 3
I am reading this article about Math.max()
and just wondering why the example given uses the spread syntax?
Can’t it be written simply as Math.max(array1)
?
const array1 = [1, 3, 2];
console.log(Math.max(...array1));
// expected output: 3
Math.max takes a list of numbers, not an array. So you can use the spread syntax instead of having to use .apply() when feeding it an array of numbers.
Check out the Math.max/min example given on the apply page