The example is not particularly well chosen. map is about data transformation, so using it for a side-effect like console.log leads to confusion.
Something like the following would maybe better illustrate the point:
const myAwesomeArray = [5, 4, 3, 2, 1]
const squares = myAwesomeArray.map(x => x * x)
Even with your example, it will be not that clear. I think the difference is made by the definition. But anyway, I will update the code with your example. Thanks
It's at least clearer that the intent of map is returning an array with modified data, not performing an action on each element.
I totally agree. I've updated the example with yours. Thanks again for your suggestion.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.