Counting - console.count
suggest changeconsole.count(label) keeps a counter for a label string. The argument is converted with ToString. A missing argument, or undefined, uses the label "default". The empty string is its own label and does increment. The console shows:
label: X
Counters match label text, not object identity. Two different functions share a counter only when their string forms are the same.
An object’s string form is used even when you pass a variable:
const o1 = 1; const o2 = '2'; const o3 = "";
console.count(o1);
console.count(o2);
console.count(o3);
console.count(1);
console.count('2');
console.count('');
Displays:
1: 1
2: 1
: 1
1: 2
2: 2
: 2
The number 42.3 and the string "42.3" share a counter because both labels are the string "42.3", not because the string is turned into a Number:
console.count(42.3);
console.count(Number('42.3'));
console.count('42.3');
Displays:
42.3: 1
42.3: 2
42.3: 3
A function’s label is its source text. These do not share one Function counter:
console.count(function(){});
const fn1 = function myfn(){};
console.count(fn1);
console.count(Number);
Displays:
function(){}: 1
function myfn(){}: 1
function Number() { [native code] }: 1
undefined is treated as a missing label ("default"), including an uninitialized binding. null, NaN, and Infinity use those words as labels. window and document exist only in browsers and are counted by their own string forms.
console.count(undefined);
let obj;
console.count(obj);
console.count(Number(undefined));
console.count(NaN);
console.count(NaN + 3);
console.count(1 / 0);
console.count(String(1 / 0));
console.count(null);
Displays:
default: 1
default: 2
NaN: 1
NaN: 2
NaN: 3
Infinity: 1
Infinity: 2
null: 1
Empty string or absence of argument
A missing argument uses "default". The empty string is a different label, and its line has a blank name:
console.count(); // default: 1
console.count(''); // : 1
console.count(""); // : 2
console.count(); // default: 2