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 some questions about how this bit of JavaScript is working. I understand what it’s doing, but still have some questions.
- The use of var. My understanding is that it’s no longer best practice to use var and yet this code begins with const? Is this an oversight or is there a reason this was written this way?
- On the topic of declaring variable, why isn’t average preceded by const or let?
- Lastly how exactly does of interact with the variable number and the array?