DEV Community

Discussion on: TIL: A Basic Thing about map()

Collapse
 
lisadean profile image
Lisa Dean

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!

Collapse
 
lionelrowe profile image
lionel-rowe • Edited

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.

Thread Thread
 
lexlohr profile image
Alex Lohr

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.

Thread Thread
 
lisadean profile image
Lisa Dean

Definitely, I thought it was an elegant shortcut to having to do a map then console.log for example purposes.