Are Console.count() docs incorrect?

Please forgive if this is the wrong place to post this but I have tried running the example in the Console.count() documentation (https://developer.mozilla.org/en-US/docs/Web/API/Console/count) and I get a different answer on node and jsbin than the docs say I should get.

Specifically:

var user = "";

function greet() {
  console.count();
  return "hi " + user;
}

user = "bob";
greet();
user = "alice";
greet();
greet();
console.count();

Running $ node -v && node main.js gives:

v10.15.0
default: 1
default: 2
default: 3
default: 4

Where the last line prints 4 whereas the docs say it should print 1.

1 Like

I’ve tested it too in the browser JS console, and the behaviour is exactly as you specify, both in Firefox and Chrome. I’ve updated the text on the page to better explain what happens. Thanks for reporting!

I can only think that perhaps the behaviour has changed since we first wrote this page. It does make sense — if you want a global count, you don’t use a label. If you want different counts for different lines, use labels. If it were not like this, there would be no way to get a global count for all count() instances in different places.

2 Likes