How to get currently running function name using JavaScript ? Last Updated : 17 Dec, 2019 Comments Improve Suggest changes 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 currently running function name using JavaScript ? H harshcooldude700 Follow Improve Article Tags : Web Technologies JQuery jQuery-Misc Similar Reads How to Get the Current URL using JavaScript? Here are two different methods to get the current URL in JavaScript.1. Using Document.URL PropertyThe DOM URL property in HTML is used to return a string that contains the complete URL of the current document. The string also includes the HTTP protocol such as ( http://).Syntaxdocument.URLReturn Val 1 min read 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 a JavaScript Function using an onsubmit Event ? HTML has a form element that is used to get the data from the user and send the data to the server. Before the HTML form sends data to the server, it generates an event called "submit". This event can be utilized to execute a JavaScript function that can either validate the form data or notify the u 3 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 measure time taken by a function to execute using JavaScript ? This article will show how to measure the time taken by a function to execute using Javascript. To measure the time taken by a function to execute we have three methods: Table of Content Using the Using Date ObjectUsing the performance.now() methodUsing the console.time() methodMethod 1: Using the U 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 How to Get the Path of Current Script using Node.js ? In Node JS, getting the path of the current script is useful for file operations, logging, and configuration. It allows you to access related files or directories reliably, regardless of where your Node.js process was started.ApproachTo get the path of the present script in node.js we will be using 2 min read Like