JavaScript Console timeEnd() Tutorial

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

Note: we’re assuming you’re already familiar with the JavaScript console time() method.

JavaScript Console timeEnd() Method

The `timeEnd()` method is used to end a timer that is started via the `time()` method.

The method takes one argument (optional) and that is the name of the label that we set for a timer when we called the `time()` method.

Basically, the label that we pass to the `timeEnd()` method, specifically will end the timer that has this label.

As a result, this method will print the amount of time that was counted by that timer to a browser console.

Note: the printed result is in milliseconds.

Console timeEnd() Method Syntax:

console.timeEnd(label);

Console timeEnd() Method Parameter:

The method takes one argument, which is optional, and that is the label of the target timer that we want to stop and get its value in a browser console.

Console timeEnd() Method Return Value:

There’s no return value from this method.

Example: using Console timeEnd() method in JavaScript

console.time("for-loop");

for(let i = 0; i<1000000; i++){

}

console.timeEnd("for-loop");

Output:

for-loop: 5.505126953125 ms
Facebook
Twitter
Pinterest
LinkedIn

Top Technologies