What will be the output of the following code snippet.?

What will be the output of the following code snippet?

let sum = 0;
const a = [1, 2, 3];
a.forEach(getSum);
print(sum);
function getSum(ele) {
sum += ele;
}

1 Like

Options:
1)6
2)1
3)3
4)none of the above

[quote=“nagesh28katke, post:1, topic:1702”]
let sum = 0;
const a = [1, 2, 3];
a.forEach(getSum);
print(sum);
function getSum(ele) {
sum += ele;
}
[/quote]let sum = 0;
const a = [1, 2, 3];
a.forEach(getSum);
console.log(sum);
function getSum(ele) {
sum += ele;
}

/*(b)What will be the output of the following code snippet?

print(typeof(NaN));

(c) What will be the output of the following code snippet?

let sum = 0;
const a = [1, 2, 3];
a.forEach(getSum);
print(sum);
function getSum(ele) {
sum += ele;
}*/

output 6

1 Like

option A) 6 - answer

the correct option 1)6

let sum = 0;
const a = [1, 2, 3];
a.forEach(getSum);
print(sum);
function getSum(ele) {
sum += ele;
}

answer is 6

answer is 6( sum of 3 nums 1+2+3 =6 )