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
()() 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.