javascript console -infinity, what does it mean?
The first argument of Function#apply
is thisArg and you are just passing the thisArg
as the array that means it's calling Math#max
without any argument.
As per MDN docs :
If no arguments are given, the result is -Infinity.
In order to fix your problem set Math
or null
as thisArg.
let max= Math.max.apply(Math, numeros );
let numeros= [1,5,10,20,100,234];
let max= Math.max.apply(Math, numeros );
console.log( max );
As @FelixKling suggested, ES6 onwards you can use spread syntax to supply arguments.
Math.max(...numeros)
let numeros = [1, 5, 10, 20, 100, 234];
let max = Math.max(...numeros);
console.log(max);