A function gets called with strange arguments and you have no idea from where. Adding a breakpoint works, but a one-line log is faster.
function save(item) {
console.trace('save called');
// ...
}
console.trace() writes a stack trace to the console. The MDN example with nested functions foo and bar prints bar, foo, <anonymous>, so you read the chain of calls top to bottom. You can pass extra values and they’re formatted like in console.log().
In some browsers the trace also includes the asynchronous events that led to the call, which is useful with promises and timers. It works in Web Workers too.
One caveat: it is a log call, so don’t leave it in production code. Every call prints a full stack, which is noisy in a loop.
You can put it in a setter to find out who changes a value, or in an event handler that fires twice. Because it prints at the moment of the call, the trace shows the path of that call and not just the function name, so you can tell whether a click handler or a timer started it.
Further reading: console.trace() on MDN