Find the Caller Function in JavaScript

Last Updated : 22 Aug, 2026

JavaScript provides the Function.caller property to identify the function that directly called the current function. It can be useful for inspecting the call chain during debugging, although it is not recommended for modern production code.

  • Use Function.caller to access the calling function.
  • The caller's name property can be used to get its name.
  • Function.caller is non-standard/deprecated and should generally be avoided in modern JavaScript.

Approach 1: Using Function.caller

Access the caller property inside the function whose caller you want to identify. The name property returns the caller function's name.

javascript
function foo() {
    console.log(foo.caller.name);
}

function bar() {
    foo();
}

bar();

Output
bar
  • foo.caller refers to the function that called foo().
  • foo.caller.name returns the caller's name.

Approach 2: Finding the Caller from Multiple Functions

The same function can be called by different functions. Function.caller identifies the function responsible for the current call.

javascript
function foo() {
    console.log(foo.caller.name);
}

function geeks() {
    foo();
}

function fun() {
    foo();
}

function sam() {
    foo();
}

geeks();
fun();
sam();

Output
geeks
fun
sam

Note: Function.caller is deprecated and non-standard. It may not work in strict mode and should not be used for new production code.

For modern applications, it is better to pass the caller information explicitly when needed:

JavaScript
function foo(callerName) {
    console.log(callerName);
}

function bar() {
    foo("bar");
}

bar();

Output
bar
Comment