Array Reduce Sum
Multiple Choice Medium
Question
What does [1,2,3].reduce((a,b) => a+b, 0) return?
Hint
reduce accumulates a single value.
Explanation
[1,2,3].reduce((a,b) => a+b, 0) starts with 0, then adds each element: 0+1=1, 1+2=3, 3+3=6. reduce is powerful for summing, finding max/min, or transforming an array into any single value. The second argument (0) is the initial accumulator value.
Related Resources
Related Lessons
- Arrays
Learn JS arrays.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.