Thanks for the article. I don't fully understand the difference between your Array#tap and the built-in Array#forEach.
Array#tap
Array#forEach
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.
forEach
undefined
map
[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!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks for the article. I don't fully understand the difference between your
Array#tap
and the built-inArray#forEach
.Hey Dor, thanks for your message!
The simple difference is that the
forEach
method will not return anything exceptundefined
. This is a problem! Since we want to map to a function but still continue the chain calls ofmap
s. So we cannot do something like that in JavaScript.Since it will return
undefined
, you will get an error trying to chain call themap
method on anundefined
value.I'll add that to my post because I think it can benefit to others. Thanks again for your question!