Alternatives to console.log()

2022-08-05

The other day I found a nice thread 🧵 (opens new window) explaining different console methods, that can be used instead of console.log(). Let us take a closer look! 🤓

# console.dir()

This method will display an interactive view of the object you want to log.

console.dir

# console.table()

This method will display a table view of the object you want to log.

console.table

Had some issues with this method in chrome where it would not display the last item in the table 🤷

# console.group() and console.groupEnd()

These methods allow you to group your console output together.

console.group

# console.time() and console.timeEnd()

These methods allow you to start and stop a timer and log the duration of the commands executed in between.

console.time

# console.count()

This method let's you count how often you have called a specific console.count().

console.count

# console.assert()

This method writes an error message to the console if the assertion is false. If it is true, nothing is logged.

console.assert

# Done!

Now you have a couple of alternatives to console.log() in your tool belt. Have fun with it!

Thanks for this awesome thread 🧵 (opens new window) @codeforreal_ (opens new window) 💪