Categories
JavaScript Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *