forEach is a mutating function which changes the value directly. Hence no return statement in iterator. And also forEach doesn't return any value.
map is non-mutating and pure function. So it's iterator needs to return a value for every iteration, otherwise it will go as nothing received, hence null . In the end, map returns a new transformed array, leaving the input array intact.
Examples:
const input = [1,2,3];
// Map:
const power = input.map(num => num * num);
console.log(power); // [1, 4, 9]
console.log(input); // [1, 2, 3]
// ForEach:
const increasedByTwo = input.forEach(num => num += 2);
console.log(increasedByTwo); // undefined
console.log(input); // [3, 4, 5]
P.S. Shameless effort to promote; as google was not consulted, let me lead you to a good article written by me π time2hack.com/2017/10/iterating-data-with-map-redβ¦