Array methods express transformations without manual loops—core of modern JS style.
Roles
map— transform each element (same length)filter— keep elements matching predicatereduce— accumulate to single value
Immutability
Return new arrays—do not mutate during map unless intentional performance trade-off.
Important interview questions and answers
- Q: map vs forEach?
A: map returns new array; forEach for side effects only. - Q: reduce initial value?
A: Always pass seed for empty-safe sums and objects.
Self-check
- What does filter return?
- Why pass 0 to reduce sum?
Tip: Re-run the playground code for map-filter-reduce and tweak one line before the MCQs.
Interview prep
- reduce seed?
Initial accumulator—required for safe empty sums.