I have written this bit of code that sums the values of array. Can some one please explain why I'm getting undefined in the last console.log statement.
var array = [2,3,4,5,6,7];
var sum = 0;
for(var i = 0; i < array.length; i++) {
sum = array[i] + sum;
}
console.log(sum);
console.log(array[i]);
iwould give you the answer.i < array.lengthreturns true, you'd still be in your for loop.