JavaScript conditions and array loops

for...of visits array values. let allows the accumulator binding to change, while const keeps the array binding fixed.

JavaScript
const values = [-2, 0, 3, 5];
let total = 0;
for (const value of values) {
  if (value > 0) total += value;
}
console.log(total);
if (total !== 8) throw new Error("Unexpected total");
Read the full lesson