forEach with function calling or anonymous function inside

Hello guys , i’m a bit confused with the use of direct call function vs anonymous function within the forEach iterator. I cannot find again the exercise but i saw some exercises to use this first bold line below instead the other one :

**a.forEach(doSomethinig)**         vs     a.forEach(el => doSomething(el))     
 //  are they the same?

function doSomething(x){

Hope someone can understand. Maybe i’m wrong but in the exercises the only answer correct was the first one in order to pass the test.


a.forEach(el => doSomething(el))

you make an anonymous arrow function (using =>) calling a named function (doSomething). so its a double wrap.

I would use either a named function:

function doSomething(x){


or an anonymous function:

a.forEach(el => {
    //body of anonymous function

so double wrap it is not ok? what if ‘doSomething’ has multiple parameters?
i’ve read on the internet that if the function has parameters, it needs to be wrapped into an anonymous function. i’m confused

why would you want two layers of wrapping? Can only be confusing in the long run

Do you still have the source for this?

that is totally fine:

function doSomething(val, index){
   console.log(val, index);

['a', 'b', 'c'].forEach(doSomething)

the logic in the .forEach method provides the arguments to your call-back function