Why do map and filter iterators require to be defined by a variable while forEach doesn't?

What’s the reason for map and filter requiring a variable while forEach doesn’t?

Is it because you are making a new array and the array made by the iterators map and filter are being saved under that variable whilst foreach doesn’t do that?

Just curious.

I think that is the reason:

Because .forEach does not save the result as an array. And the others I think are because the result is an array and arrays need to be saved to a variable.

1 Like