Last Updated: February 25, 2016
·
635
· 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 );