18.
What will be the output of the following code?
const numbers = [1, 2, 3, 4, 5];
const sum = numbers.reduce(function(accumulator, currentValue) {
return accumulator + currentValue;
}, 0);
console.log(sum);
25
15
10
6
Correct: B
The code calculates the sum of all the elements in the array using the reduce() method. The initial value of the accumulator is 0. Since the sum of the numbers in the array is 15, the output will be 15.