Home > Web Front-end > JS Tutorial > body text

Introduction to the console.trace() function in JavaScript

高洛峰
Release: 2017-02-03 14:55:03
Original
2200 people have browsed it

When debugging a JavaScript program, sometimes you need to print the stack information of function calls. This can be achieved by using console.trace(). Take the following code as an example:

function doTask(){
    doSubTask(1000,10000);
}
 
function doSubTask(countX,countY){
    for(var i=0;i<countX;i++){
        for(var j=0;j<countY;j++){} 
    }
    console.trace();
}
doTask();
Copy after login

Insert a line of console.trace() statement at the end of the execution of the doSubTask() function, which will print the function call stack information there in the debugging console. For example, in the Firebug console it looks like this:

Introduction to the console.trace() function in JavaScript

In the Firebug console, console.trace() will not only print the function call stack information, but also display each function call. The value of the parameter.

Browser support

console.trace(), like console.log(), is better supported by browsers with debugging tools. All major browsers support this function.

For more articles related to the console.trace() function in JavaScript, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template