How to get currently running function name using JavaScript ? Last Updated : 17 Dec, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report Given a function and the task is to get the name of function that is currently running using JavaScript. Approach 1: Using arguments.callee method: It refers to the currently executing function inside the function body of that function. In this method, we use arguments.callee to refer to the name of the function. So we define a new variable as arguments.callee.toString(). Then we use (variable_name).substr to get the function and then we display it as an alert. Syntax: arguments.callee.toString() You may have to parse the name though, as it will probably include some extra junk. Example 1: This example display currently running function using arguments.callee method. javascript <!DOCTYPE HTML> <html> <head> <title> How to get currently running function name using JavaScript ? </title> </head> <body style = "text-align:center;"> <h1 style = "color:green;" > GeeksForGeeks </h1> <script> function GFGs() { var me = arguments.callee.toString(); me = me.substr('function '.length); me = me.substr(0, me.indexOf('(')); alert(me); } GFGs(); </script> </body> </html> Output: Approach 2: With the help of console.log method, we define a new function which returns the name of the function and call it the present function. Syntax: function getFuncName() { return getFuncName.caller.name } function teddy() { console.log(getFuncName()) } teddy() Example 2: This example display currently running function using console.log method. javascript <!DOCTYPE html> <html> <head> <title> How to get currently running function name using JavaScript ? </title> </head> <body style = "text-align:center;"> <h1 style = "color:green;" > GeeksForGeeks </h1> <script> function getFuncName() { return getFuncName.caller.name } function teddy() { console.log(getFuncName()) } teddy() </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to get the function name from within that function using JavaScript ? H harshcooldude700 Follow Improve Article Tags : Web Technologies JQuery jQuery-Misc Similar Reads How to get the function name from within that function using JavaScript ? Given a function and the task is to get the name of the function from inside the function using JavaScript. There are basically two methods to get the function name from within that function in JavaScript. These are: Using String substr() MethodUsing Function prototype name propertyGet the Function 2 min read How to get current function name in PHP? The function name can be easily obtained by the __FUNCTION__ or the __METHOD__ magic constant. Method 1 (Prints function name): __FUNCTION__ is used to resolve function name or method name (function in class). Example: php <?php class Test { public function bar() { var_dump(__FUNCTION__); } } fun 1 min read How to call function from it name stored in a string using JavaScript ? In this article, we will call a function from the string stored in a variable. There are two methods to call a function from a string stored in a variable. Using window object methodUsing eval() method Note: The eval() method is older and is deprecated. Method 1: Using the window object. The window 2 min read How to Check a Function is a Generator Function or not using JavaScript ? Given an HTML document containing some JavaScript function and the task is to check whether the given function is generator function or not with the help of JavaScript. There are two examples to solve this problem which are discussed below: Example 1:In this example, we will use functionName.constru 2 min read How to execute a function when its name as a string in JavaScript ? To execute a function when its name is a string in JavaScript, we have multiple approaches. In this article, we are going to learn how to execute a function when its name is a string in JavaScript. Example: function myFunction() { ...}const functionName ="myFunction";Below are the approaches used to 3 min read How to override a JavaScript function ? In this article, we are given an HTML document and the task is to override the function, either a predefined function or a user-defined function using JavaScript. Approach: When we run the script then Fun() function is called. After clicking the button the GFG_Fun() function is called and this funct 2 min read Like