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
//   first

Calling 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.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships