Most of the time we faced issues debugging a function or piece of code. Understanding how the execution flows, for that console.trace() method is used.
The console.trace() method is used to print the stack trace that shows how the code is executed or the code flow in the web console. This method logs the call stack that exists at the point of what console.trace() method is invoked. It is used to find an error in the function that is being called from different places in the code. It is work by placing the console.trace() method in the code at the place where we want to trace the code from. It accepts an argument that is displayed as a label for the particular stack trace.
- data – This is an optional parameter. data can be any object that needs to be printed along with the trace to the web console.
What we discussed above is given in the below example.
Output: Press F12 and go to the Console section
About the Author: Pranaya Rout
Pranaya Rout has published more than 3,000 articles in his 11-year career. Pranaya Rout has very good experience with Microsoft Technologies, Including C#, VB, ASP.NET MVC, ASP.NET Web API, EF, EF Core, ADO.NET, LINQ, SQL Server, MYSQL, Oracle, ASP.NET Core, Cloud Computing, Microservices, Design Patterns and still learning new technologies.