Function calling in Javascript with double brackets

后端 未结 5 480
小蘑菇
小蘑菇 2021-02-06 13:23

When I call function hi()() with double brackets the function displays hi output and it will also give error saying, that hi is not functi

5条回答
  •  遥遥无期
    2021-02-06 13:52

    ()() means calling a function and if returns another function second parenthesis will call it.Please find below example :

    function add(x){
        return function(y){
            return x+y;
        }
    }
    

    add(3)(4)

    output: 7

    in above case add(4) will be called for add function and add(3) will be called for returned function. here value of parameter x is 3 and parameter y is 4.

    Please note : we use parenthesis for function call.

提交回复
热议问题