Tuesday, 2 October 2018

node.js: console.count([label]): Maintains internal counter for the label

console.count([label])
It maintains internal counter for the label. When you call this method, it prints the number of times console.count() has been called with the given label.

HelloWorld.js
var hello = "Hello World";
var welcome = "Good Morning"

console.count(hello);
console.count(welcome);
console.count(hello);
console.count(hello);
console.count(welcome);

Output
Hello World: 1
Good Morning: 1
Hello World: 2
Hello World: 3
Good Morning: 2


If you do not pass any argument to count() method, then it takes the string 'default' as DEFAULT value.

HelloWorld.js
console.count();
console.count('default');
console.count('default');
console.count();


Output
default: 1
default: 2
default: 3
default: 4


Previous                                                 Next                                                 Home

No comments:

Post a Comment