Skip to content

How to Find out the Caller Function in JavaScript

To find out the caller function, use the non-standard function.caller property in JavaScript. Replace function with the name of the function whose caller you want to identify.

JavaScript caller function

Output appears here after Run.

If the function Welcome was invoked by the top-level code, the value of Welcome.caller is null; otherwise, it is the function that called Welcome.

INFO

function.caller is a non-standard feature and is not part of any web standard. Avoid using it in production websites, as it may not work consistently across all browsers. Additionally, it only returns the immediate caller, not the full call stack. For modern debugging, use Error().stack or console.trace() instead.

There is another method which is no longer supported in modern JavaScript:

JavaScript caller function

Output appears here after Run.

JavaScript caller function

Output appears here after Run.

The function.caller property was introduced to replace the obsolete arguments.caller property. arguments.caller used to provide the function that called the currently executing function, but it has been removed from modern JavaScript.

WARNING

Though it may still work in some major browsers, its use is not recommended, as it could be removed at any time. Note that in strict mode or ES modules, function.caller returns null, and arguments.callee throws a TypeError.

The function.caller Property

The function.caller property returns the function that called the specified function. It will return null for strict, generator function callers and async function.

Dual-run preview — compare with live Symfony routes.