Grow Beyond Console.log()

Chidozie Duru
LearnFactory Nigeria
3 min readOct 11, 2020

Interestingly, a number of developers do not maximize the juice in the JavaScript console object. There are quite a couple of methods in the console object that could help one debug code effectively and we will take a deep dive and talk about them right away.

1. console.log()

2. console.error()

3. console.warn()

4. console.clear()

5. console.table

6. console.time() and console.timeEnd()

7. console.group() and console.groupEnd()

8. console.count()

9. console.assert()

10. console.trace()

So here we go:

  1. Console.log() -this is used to log messages to the console. Anything could be displayed in the console and this includes arrays, strings, integers, objects, boolean e.t.c.

2. Console.error()-this is used to log error messages to the console. These error messages appear in red color on the console.

3. Console.warn()-this is used to log warning messages to the console. These warning messages appear in yellow color on the console.

4. Console.clear()-this will usually clear the console and leave a message “console was cleared” in Chrome browser while Mozilla Firefox browser will only clear the console.

5. Console.table()-this happens to be a very interesting method of the console object. It prints a table in the console from object argument passed into it.

6. Console.time() and Console.timeEnd()-this method can be used to calculate the amount of time spent on parsing a block of code or function.

7. Console.group() and Console.groupEnd()-these methods together can be used to group our messages in the console.

8. Console.count()-this method is used to count the number that the function hit by this counting method.

9. Console.assert()-this method takes two arguments. The first argument is the condition while the second is an output to be logged to the console. The output will be logged if the condition is not satisfied.

9. Console.trace()-this method will log a stack trace that shows how the code ended up at a certain point.

Now with these new superpowers, there is so much more we can do. Go for it where necessary.

👏

--

--