You can pass basically any function as the callback to map, but if the callback itself returns undefined (like console.log does) the resulting array won't be very useful. In that case, it becomes basically the same as forEach, because the side effects of the callback still happen.
This is less about .map than about console.log. If you want to know what argument a callback receives, you can just drop in console.log and will instantly see them. A neat trick for introspection.
You can pass basically any function as the callback to
map
, but if the callback itself returnsundefined
(likeconsole.log
does) the resulting array won't be very useful. In that case, it becomes basically the same asforEach
, because the side effects of the callback still happen.This is less about
.map
than aboutconsole.log
. If you want to know what argument a callback receives, you can just drop in console.log and will instantly see them. A neat trick for introspection.Definitely, I thought it was an elegant shortcut to having to do a
map
thenconsole.log
for example purposes.