How to call a function that return another function in JavaScript ? Last Updated : 11 Jan, 2024 Comments Improve Suggest changes Like Article Like Report 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. Approach:Define Outer Function:Create an outer function that takes parameters and contains the logic for processing or initializing data.Return Inner Function:Inside the outer function, return another function (inner function). This inner function can access variables and parameters from the outer function due to closure.Call Outer Function:Call the outer function to obtain the inner function. Assign the result to a variable if needed.Invoke Inner Function:Call the returned inner function separately, either immediately or at a later point in your code.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() OutputFrom function fun2Example 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() OutputFrom function fun2 Alert from fun2 Comment More infoAdvertise with us Next Article How to call a function that return another function in JavaScript ? P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How to find out the caller function in JavaScript? In this article, we see the methods to find out the caller function in Javascript. Sometimes, the developer may want to modify how a function works on the basis of its caller function. To find out the caller function name, we will use the Function object's caller property. Property: Function.caller 1 min read How to create a function from a string in JavaScript ? The task is to create a function from the string given in the format of the function. Here are a few approaches that are listed below: Using Function() ConstructorUsing eval() MethodApproach 1: Using Function() ConstructorUse the Function() Constructor to create a function from the string.It accepts 2 min read How to implement a function that enable another function after specified time using JavaScript ? Let us assume that we have been given a function add() which takes in two parameters a and b, and returns their sum. We are supposed to implement a function that should be able to call any function after the given delay amount of time. This can be done with the approaches as given below: Approach 1: 2 min read How to create a function that invokes function with partials prepended arguments in JavaScript ? In this article, we will see how to create a function that invokes functions with partials prepended to the arguments it receives in JavaScript. Before understanding the problem statement and approaching the solution for the same, let's, first of all, know what a function (also called a method) is a 5 min read How to pass an array as a function parameter in JavaScript? Here are different ways to pass an array as a function paramter in JavaScript.1. Using apply() MethodThe apply() method invokes a function with a specified `this` value and an array of arguments. It takes two parameters: the first is the `this` context for the function, and the second is an array of 2 min read How to Call a JavaScript Function from an onsubmit Event ? The onsubmit event attribute in HTML is triggered when a form is submitted. It is also useful for validating form data or performing actions before any submission and ensures better control and validation of user inputs before data is sent. The below methods can be used to call a JavaScript function 2 min read How to convert an asynchronous function to return a promise in JavaScript ? In this article, we will learn how to convert an asynchronous function to return a promise in JavaScript. Approach:Â You need to first declare a simple function (either a normal function or an arrow function (which is preferred)). You need to create an asynchronous function and then further you need 3 min read How To Return the Response From an Asynchronous Call in JavaScript? To return the response from an asynchronous call in JavaScript, it's important to understand how JavaScript handles asynchronous operations like fetching data, reading files, or executing time-based actions. JavaScript is a single-threaded nature means it can only handle one task at a time, but it u 3 min read Function that can be called only once in JavaScript In JavaScript, you can create a function that can be called only once by using a closure to keep track of whether the function has been called before. JavaScript closure is a feature that allows inner functions to access the outer scope of a function. Closure helps in binding a function to its outer 3 min read How to Delay a Function Call in JavaScript ? Delaying a JavaScript function call involves executing a function after a certain amount of time has passed. This is commonly used in scenarios where you want to postpone the execution of a function, such as in animations, event handling, or asynchronous operations. Below are the methods to delay a 2 min read Like