Sometimes, we want to print JavaScript exception stack trace.
In this article, we’ll look at how to print JavaScript exception stack trace.
How to print JavaScript exception stack trace?
To print JavaScript exception stack trace, we can use the stack property of an Error instance.
For instance, we write
console.log(new Error().stack);
to create a new Error instance and then get the stack trace from the stack property.
Then we use console.log to log the stack trace.
We put this in the line where we want to print the stack trace to the console.
Conclusion
To print JavaScript exception stack trace, we can use the stack property of an Error instance.