DEV Community

Cover image for In JavaScript Console Other Than Console.log()
Kamran Ahmad
Kamran Ahmad

Posted on

In JavaScript Console Other Than Console.log()

  1. Console.count()

Let assume you want to keep a count of how many click the user makes on the button. The code with .log() might look like this

let userClickCounter = 0;
function watchUserClicks(){
userClickCounter++;
console.log("User Clicked ${userClickCounter}")
}
<button onclick = "watchUserClicks()">
Click Me to Without pause
</button>
Enter fullscreen mode Exit fullscreen mode

The other method is also present

function watchUserClick(){
consol.count('User Click');
}
<button onclick = "watchUserClicks()">
Click Me to Without pause
</button>
Enter fullscreen mode Exit fullscreen mode

Here the need for variable and its related code is eliminated thereby, making the code optimal and readable.

  1. Console.Dir()

This method shows all the properties of the JS Object.
The console.log() print out toString representation whereas consol.dir() print out a navigation tree

see the difference:-

Image description

This method come to the real help when you want to show a single Dom Element like this
Image description

  1. Console.Time() and Console.ThimeEnd()

When you are working on a complex algorithm. time is one of the main factor you need to look on simultaneously.

this is where you can use these console method to know how much time your algorithm is taking to execute.
Image description

  1. Console.table()

the best method vs console.log() to show an object In JS. this method is used to represent complex object or arrays in tabular format.
Image description

buymeacoffee

Top comments (0)