7.
What is the output of the following code?
const numbers = [1, 2, 3, 4, 5];
let sum = 0;
numbers.forEach(function(num) {
sum += num;
});
console.log(sum);
0
10
15
5
Correct: C
The forEach() method iterates over each element in the array and performs a specified action. In this case, the callback function adds each number to the sum variable. After iterating through all the numbers in the array, the sum variable will hold the total sum of all the numbers, which is 15. Therefore, the output will be 15.