About javascript console.time ()?

console.time () and console.timeEnd () can print the execution time of the program.

(function(){
    console.time("index");
    var div = document.getElementById("div");
    div.onclick = function(){
        alert("123");
    };
    console.timeEnd("index");
}());

question: why is the time printed when it is not clicked?


because div.onclick = function () {.} is just an assignment operation.

in your code, console.time only counts the time taken by
var div =. (ignoring the behavior of getBy. , simplifying the problem)
div.onclick =.
these two assignment operations.


console.timeEnd ('index'); not in the click event. The click event in


code only executed alert (' 123');

Menu