An Interest In:
Web News this Week
- April 2, 2024
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
July 14, 2022 09:26 pm GMT
Original Link: https://dev.to/codepo8/the-browser-console-has-a-count-method-5cj7
The browser console has a count method
When debugging or analysing JavaScript, you often see people trying to find out how often a certain function is called. The common way to do that is to use a global counter variable to increment and log in the function.
var i = 0;function test(){ // other functionality i++; console.log(i); // other functionality}
There is, however, a better method. The Console of the browser has a count()
and countReset()
method that event takes a label. That means you can avoid the global.
function bettertest(){ console.count('bettertest');}
You can see it in action in this screencast.
This is part of the standard Console API and should be supported in all browsers.
Original Link: https://dev.to/codepo8/the-browser-console-has-a-count-method-5cj7
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To