Do you know what will be the output of this code?
JavaScript
function sum(a, b) {
return this.base + a + b;
}
console.log(sum.apply({ base: 1 }, [2, 3]));
Show answer and explanation
The answer is 6.
apply calls sum with this set to { base: 1 } and spreads the array into arguments: 1 + 2 + 3. The call equivalent is sum.call({ base: 1 }, 2, 3).