Have a doubt in functions, Can some one explain?


I need to add 2 numbers by passing parameters, but why is it giving me the error?

Hi @vaishnavi_A.N

You’re calling addInner instead of returning it. You should change addInner(); to return addInner;

Cheers,
Michael

1 Like

Thank you @mikoMK, I thought by calling that function, it will automatically return the inner Function.

Unfortunately not. Traditional function return undefined when you don’t use the return keyword. (Arrow functions will return the result of the last statement even without return.)

In your example add(2) will return undefined and then the browser tries to call undefined(3). Hence the error “add(…) is not a function”, because it’s undefined instead.

1 Like

Thank you so much @mikoMK , You are a saviour me for me.
I have encountered the same problem today and I just referred your above statement.
Thank you Again, I owe u a lot.
:smiley: :smiley: :+1:

1 Like