Array map vs forEach Quiz
Question
What is the key difference between `array.map(fn)` and `array.forEach(fn)`?
Hint
One returns a new array, the other is for side effects.
Explanation
map calls the callback on each element and returns a new array of the results — it does not modify the original. forEach calls the callback on each element but returns undefined — it is used for side effects (like logging). Neither modifies the original array (though the callback could). Use map when you need transformed values, forEach when you just need to iterate.
Related Resources
Related Lessons
- JavaScript Arrays
Learn about array iteration methods.
Related Reference
- JavaScript Array Reference
Reference for map and forEach.
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.