What is the result of [1, 2, 3].map(x => x * 10)?
Options
- undefined
- [10, 20, 30] (Correct option)
- 60
- [1, 2, 3]
Answer
[10, 20, 30]
Why
map calls the function on each element and returns a NEW array with the results; the original is unchanged.
forEach also calls the function on each element, but returns undefined; use it only for side effects like logging.
Related: filter keeps elements where the function returns true; reduce combines everything into one value.
Remember
map → new array of results. forEach → nothing returned.