Search code examples
javascriptclosuresfunction-callsfunction-parameter

Confusion about variables equaling functions JavaScript


I have these functions:

function change(num1, num2){
    //return number
}

function getFunction(funct){
    //return function
}

this declaration:

var funct = getFunction(change);

and this call

funct(array);

I am confused about what the call does. Where does it send array, what exactly is it doing? I just can't wrap my head around it. When sending the function change() into getFunction() what exactly does this do and again how does JS handle funct(array)? Let me know if I need more info.


Solution

  • getFunction returns a function.

    var funct = getFunction(change);
    

    funct is now assigned to the returned function reference

    funct(array) is just calling the function returned from the previous assignment.