Ok, that makes total sense and that kind of idea was probably how I ended up assuming incorrectly. There IS another option for "nothing" other than null and undefined in an array. Also, I just learned you could map a console.log. Two TIL for the price of one!
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.
Ok, that makes total sense and that kind of idea was probably how I ended up assuming incorrectly. There IS another option for "nothing" other than
null
andundefined
in an array. Also, I just learned you could map aconsole.log
. Two TIL for the price of one!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.