For instance, say I have
var numbers = [5, 6, 2, 3, 7];
var max = Math.max.apply(null, numbers);
console.log(max);
or,
var numbers = [5, 6, 2, 3, 7];
var max = Math.max.call(null, ...numbers);
console.log(max);
Why would I choose call
or apply
over something similar to the below?
var numbers = [5, 6, 2, 3, 7];
var max = Math.max(...numbers);
console.log(max);
I've been able to get away with coding in Javascript without using either of these two methods (or bind
) but I'd like to know if I should start using them.