Last Updated: February 25, 2016
·
882
· jussi-kalliokoski

Log stack trace in JS

I often have to debug mobile devices etc. where using the debugger statement isn't a viable option either because there's no way to observe the breakpoint or setting up a way to do it would be overly tedious.

Other times I might not want to break execution when the code point gets run often, but I want to see if there are any deviances in the call stack of that code point.

In these cases I've found that the easiest way to log the stack trace is to use the stack attribute of an error, like this:

console.log( Error().stack );

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside