Which fix removes the bug?
const total = 0;
for (const n of [1, 2, 3]) {
total += n;
}
- Declare total with
let - Use
for...infor the loop - Start total at
null - Add a
return totalline
A const binding cannot be reassigned, so
Play Problem Solving ▸
+= throws a TypeError.