Wednesday, January 21, 2026
HomeLanguagesJavascriptHow to call a function that return another function in JavaScript ?

How to call a function that return another function in JavaScript ?

The task is to call a function that returns another function with the help of JavaScript is called a Currying function, a function with numerous arguments that can be converted into a series of nesting functions with the help of the currying method.

We’re going to discuss a few techniques. 

Approach:

  • First, call the first function-1.
  • Define a function-2 inside function-1.
  • Return the call to function-2 from function-1.

Example 1: In this example, “from function 2” is returned from the fun2 which is finally returned by fun1

Javascript




function fun1() {
    function fun2() {
        return "From function fun2";
    }
    return fun2();
}
 
function GFG_Fun() {
    console.log(fun1());
}
GFG_Fun()


Output

From function fun2

Example 2: In this example, “Alert from fun2” is returned from the fun2 along with an alert, Returned value is finally returned by fun1

Javascript




function fun1() {
    function fun2() {
        console.log("From function fun2");
        return "Alert from fun2 ";
    }
    return fun2();
}
 
function GFG_Fun() {
    console.log(fun1());
}
GFG_Fun()


Output

From function fun2
Alert from fun2 
RELATED ARTICLES

Most Popular

Dominic
32475 POSTS0 COMMENTS
Milvus
119 POSTS0 COMMENTS
Nango Kala
6847 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12064 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7220 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6912 POSTS0 COMMENTS