JavaScript Console trace() Tutorial

In this section, we will learn what the console trace() method is and how to use it in JavaScript.

JavaScript Console trace() Method

The `trace()` method is used to print the track of running scopes in the stack of the current program.

Basically, using this method, you can see where your program started and where it is now!

Console trace() Method Syntax:

console.trace(label)

Console trace() Method Parameter:

The method takes one optional argument as well (This argument is known as label). This label then will be printed on the console along with the stack trace.

Console trace() Method Return Value:

The method does not return a value.

Example: using Console trace() method in JavaScript

function func1(){
  func2();
}
function func2(){
  func3();
}
function func3(){
  console.trace("Hello from the func3");
}
func1();

Output:

Hello from the func3

func3

func2

func1

(anonymous)

Leave a Reply