Which console methods are worth knowing beyond console.log?
There are about twenty, and a handful of them earn their place in real debugging work.
console.log("a message");
console.info("informational");
console.warn("something looks odd");
console.error("something failed");
console.group("Grouped output");
console.log("inside the group");
console.groupEnd();
// Timed output.
console.time("work");
for (let i = 0; i < 100000; i++) { /* do some work */ }
console.timeEnd("work");
// A table of objects.
console.table([
{ id: 1, name: "Ada" },
{ id: 2, name: "Bob" },
]);
// Counters.
console.count("iteration");
console.count("iteration"); // iteration: 2
console.assert(false, "this will be reported");The two that save the most time are the table method and the timer methods. The table method renders a list of objects as an aligned table, so you can see all the fields of every row at once instead of scrolling through separate log lines. And console.time with console.timeEnd gives you a measured duration, which turns a vague claim that something is slow into a number you can compare before and after a change.
The grouping methods are for structure. When a function logs twenty things, wrapping them in a group with a label turns a wall of output into readable sections.
The count method is surprisingly useful. Add a count to the top of a branch and you can see at a glance whether that branch runs once or a hundred times, which answers a surprising number of bugs in a single line.
And console.assert logs a message only when the condition is false. It is not a replacement for a real assertion in a test suite, but it is a quick way to record an invariant while you are exploring code.