Back to Content

console: trace() static method

files/en-us/web/api/console/trace_static/index.md

latest1.5 KB
Original Source

{{APIRef("Console API")}} {{AvailableInWorkers}}

The console.trace() static method outputs a stack trace to the console.

[!NOTE] In some browsers, console.trace() may also output the sequence of calls and asynchronous events leading to the current console.trace() which are not on the call stack — to help identify the origin of the current event evaluation loop.

See Stack traces in the {{domxref("console")}} documentation for details and examples.

Syntax

js-nolint
console.trace()
console.trace(object1, /* …, */ objectN)

Parameters

  • objects {{optional_inline}}
    • : Zero or more objects to be output to console along with the trace. These are assembled and formatted the same way they would be if passed to the {{domxref("console/log_static", "console.log()")}} method.

Return value

None ({{jsxref("undefined")}}).

Examples

js
function foo() {
  function bar() {
    console.trace();
  }
  bar();
}

foo();

In the console, the following trace will be displayed:

plain
bar
foo
<anonymous>

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also