JavaScript · Junior · Question 23 of 75
What does [1, 2, 3].forEach(x => x * 2) return?
- ✓Correct answer:
undefined - 2
[2, 4, 6] - 3
[1, 2, 3]
Explanation
forEach is for side effects and always returns undefined. Use map to get a new array. Another difference: you can't break out of forEach - use for...of, some or find for that.