DEV Community

loading...

Discussion on: Why you need the tap method

Collapse
aminnairi profile image
Amin Author • Edited

Hey Dor, thanks for your message!

The simple difference is that theforEach method will not return anything except undefined. This is a problem! Since we want to map to a function but still continue the chain calls of maps. So we cannot do something like that in JavaScript.


[1, 2, 3].map(something).forEach(console.log).map(somethingElse);

Since it will return undefined, you will get an error trying to chain call the map method on an undefined value.

I'll add that to my post because I think it can benefit to others. Thanks again for your question!

Forem Open with the Forem app