DEV Community

Discussion on: JavaScript: Higher-order Functions Part-1

Collapse
 
hexram profile image
Héctor Ramírez

Hi, Kiran.

I must confess that your article raises some questions regarding the example posted under item "3. Function return another function". I don't see the point in declaring arguments "fun1" and "fun2" for function "calc" if there is no further reference to any of them inside the declaration. While I'm no expert in Java Script, my personal experience would indicate that the code for function "calc" should be something like:


function calc(x,y, fun1, fun2){
    return function() {
        console.log(`${x} + ${y} = ${fun1(x, y)}`);
        console.log(`${x} - ${y} = ${fun2(x, y)}`);
    }
}

Enter fullscreen mode Exit fullscreen mode

Again, I am no expert in JavaScript, my point is that the passing of arguments to a function should be recognized -utilized, employed- inside the definition of the function; as shown, in your example under "3. Function return another function", I cannot relate the arguments passed to the result obtained.

Yours is an excellent article, Kiran, and my only intention is to express my very personal doubts on the matter. Thank you.

Collapse
 
kiranrajvjd profile image
Kiran Raj R

Dear Hector, thank you for pointing out the mistake, I edited the example. Please check the edit. Like you I am also not an expert, just like to share things I know, to others. If there are errors please feel free to point it out, that will help us to learn better. Good day!!!