- 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>
The other method is also present
function watchUserClick(){
consol.count('User Click');
}
<button onclick = "watchUserClicks()">
Click Me to Without pause
</button>
Here the need for variable and its related code is eliminated thereby, making the code optimal and readable.
- 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:-
This method come to the real help when you want to show a single Dom Element like this
- 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.
- 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.
Top comments (0)