How to find out where a function is called from in JavaScript?

Sometimes, we want to find out where a function is called from in JavaScript.

In this article, we’ll look at how to find out where a function is called from in JavaScript.

How to find out where a function is called from in JavaScript?

To find out where a function is called from in JavaScript, we can use the console.trace method.

For instance, we write:

const foo = () => {}
console.trace();
foo()

Then when console.trace is called, the console.trace method will log the stack trace onto the console.

Conclusion

To find out where a function is called from in JavaScript, we can use the console.trace method.