Do you know what will be the output of this code?
JavaScript
console.log([].reduce((a, b) => a + b));
Show answer and explanation
The answer is TypeError: Reduce of empty array with no initial value.
Without an initial value, reduce uses the first item as the accumulator. An empty array has no first item. Pass one as the second argument: .reduce((a, b) => a + b, 0).