Junior JavaScript

What is the difference between map() and forEach()?

Method Returns Chainable Use Case

forEach

undefin

❌ No Iteration

map() New array ✅ Yes Transformation

Example:

[1,2,3].map(x => x*2); // [2,4,6]

More from JavaScript Tutorial

All questions for this course