I detailed (and rephrased) my comment to avoid misinterpretation.
about array.map(console.log) vs array.forEach(console.log), we should avoid both of them and alaways expand the declaration of the function. Because what's being log is probably not what you want .
I'd argue that array.forEach(console.log) is acceptable in some circumstances. For example, if you're developing a new function and want to see want to log each element for debug purposes.
But generally, in a production setting, logging every element in an array is not good practice regardless of the method you choose.
I wasn't talking about the console.log, I was about the fact that a funny thing happen when you do something like [1,2,3].forEach(console.log) (same with map)
1 0 [ 1, 2, 3 ]
2 1 [ 1, 2, 3 ]
3 2 [ 1, 2, 3 ]
Because forEach and map are passing three params on each call (the element, its index and the full list) which is probably not what you want. It's true with all function that takes more than one input.
I detailed (and rephrased) my comment to avoid misinterpretation.
about array.map(console.log) vs array.forEach(console.log), we should avoid both of them and alaways expand the declaration of the function. Because what's being log is probably not what you want .
Appreciate the follow up @brieucp !
I'd argue that
array.forEach(console.log)
is acceptable in some circumstances. For example, if you're developing a new function and want to see want to log each element for debug purposes.But generally, in a production setting, logging every element in an array is not good practice regardless of the method you choose.
I wasn't talking about the console.log, I was about the fact that a funny thing happen when you do something like [1,2,3].forEach(console.log) (same with map)
Because forEach and map are passing three params on each call (the element, its index and the full list) which is probably not what you want. It's true with all function that takes more than one input.
Ah I see what point you were making now!
Then yeah, you're obviously correct 😊.
Sorry, I got the wrong end of the stick!