JavaScript · Junior · Question 23 of 75

What does [1, 2, 3].forEach(x => x * 2) return?

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.

Further reading

Problem with a question

JavaScript · Junior · question 23

Test yourself

Take the JavaScript · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz