HTML DOM
HTML DOM console trace() Method
The console.trace() method prints a stack trace to the browser's console, showing the chain of function calls that led to the point where trace() was called.
Definition and Usage
console.trace() writes a stack trace to the console. The trace lists the current call and every function that called it, in order, which helps you understand how execution reached a particular line.
Syntax
console.trace()
console.trace(message, obj1, obj2, ...)You can optionally pass a label and extra values, which are printed above the trace. It returns undefined.
Example
function first() {
second();
}
function second() {
third();
}
function third() {
console.trace("Reached third()");
}
first();
// Console prints:
// Reached third()
// third
// second
// firstCalling first() eventually runs third(), where console.trace prints the full call chain: third was called by second, which was called by first. This makes it easy to see the path the code took.
console.trace is a debugging aid only - it does not throw or stop execution. The exact formatting of the trace varies between browsers.
