Stop Using console.log() for everything in JavaScript

Denis Wachira
3 min readJul 11, 2022

--

JavaScript has more than console.log()… Use this instead

1: console.dir

The method console.dir() displays an interactive list of the properties of the specified JavaScript object. If you want to log all the properties of a HTML element, use console.dir instead of console.log. See an example below :

console.dir()

2: console.table()

The console.table() method displays tabular data as a table.

This function takes one mandatory argument data, which must be an array or an object, and one additional optional parameter columns.

It logs data as a table. Each element in the array (or enumerable property if data is an object) will be row in the table.

3: console.group()

If you have a lot of logs, it can be difficult to keep track of all these logs.

The console.group() method creates a new inline group in the Web console log, causing any subsequent console messages to be indented by an additional level, until console.groupEnd() is called.

console.group()
output

4: console.time()

The console.time() method starts a timer you can use to track how long an operation takes.

You give each timer a unique name, and may have up to 10,000 timers running on a given page.

When you call console.timeEnd() with the same name, the browser will output the time, in Milliseconds, that elapsed since the timer was started.

4: console.count()

The console.count() method logs the number of times that this particular call to count() has been called.

A string if supplied, count() outputs the number of times it has been called with that label. If omitted, count() behaves as though it was called with the “default” label.

console.count()

--

--

Denis Wachira

I am a computer science student at Kirinyaga University and specializing in web development with passionate about bringing client’s visions to life.