const arr = [1, 2, 3, 4, 5];
var sum = 0;
for (var number of arr) {
sum += number;
}
average = sum / arr.length;
console.log(average);
Hi all, I have a few questions about how this piece of JavaScript works. I understand what he’s doing, but I still have a few questions.
- The use of var. I understand that it is no longer recommended to use var and yet this code starts with constant? Is this an oversight or is there a reason it was written this way?
- On the topic of variable declaration, why isn’t the average preceded by constant Where let?
- Finally how exactly of interact with the variable Number and the table?