1 minute read
const nums = [2, 3, 4];
let sum = 0;
// Use `let i` because i mutates (`i++`).
for (let i = 0; i < nums.length; i++) {
sum += nums[i];
}
console.log(`sum: ${sum}`);
sum: 9
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.