DEV Community

Cover image for Function call call call ...
Shuvo
Shuvo

Posted on

4 1

Function call call call ...

We usually call a function by using a set on parenthesis after its name eg. fun()
but what if our function returned a function? In that case you would be able to call it again

function hello(){
    console.log("Hello");
    return () => console.log(" world");
}
hello()();
Enter fullscreen mode Exit fullscreen mode

It looks a lot normal if we use a variable in between

function hello(){
    console.log("Hello");
    return () => console.log(" world");
}
let func = hello(); //receiving the function returned from hello
func();
Enter fullscreen mode Exit fullscreen mode

but in we try to call the function third time it will give us error.
function call error

but what if your function returned itself? in that case when ever we call it we are again getting a function returned so can can keep calling it infinitely

function hello(){
    console.log("Hello");
    return hello;
}
hello()()()()()()()()()()()();
Enter fullscreen mode Exit fullscreen mode

Hope you enjoyed the article, for now cya()()()()()()

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (1)

Collapse
 
joeattardi profile image
Joe Attardi

What did I just read

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay