Skip to main content

map, filter, reduce and forEach

Pick the right method for transforming, selecting, aggregating or performing a side effect. When does reduce need an initial value?

Official Reference

Model Answer & Explanation

map transforms items, filter retains matching items, reduce accumulates a result, and forEach calls a callback for side effects and returns undefined. Without an initial accumulator, reduce uses the first present element and throws if no present element exists. Use an explicit initial value when the accumulator type differs or input may be empty.

Follow-up Interview Question · Why does awaiting forEach(async callback) not wait for its callbacks?

Module Context & References

JavaScript · Language theory Explain scope, closures, this, prototypes, equality and references
Personal Notes · Markdown

Technologies & Interview Topics Covered

Switch between short-term interview tracks and long-term 80/20 engineering depth to practice JavaScript internals, React rendering and hooks, timed frontend machine coding UI challenges, MeetaPro FG300, Blind 75 & NeetCode 150 DSA patterns, Python & FastAPI APIs, PostgreSQL query optimization & MVCC, Redis caching, Applied AI RAG pipelines & evaluations, and distributed system design.