Dive deeply inside the console object method

Mário Batalha
4 min readJan 21, 2021

--

Hi guys, in this article I decided to talk about the console object method of JS. Console object in js provides access to the browser debugging console, where you can print values of variables that you’ve used in your code. Oftentimes this can be used to debug if the right values are being passed in your code.

Most of us have used console.log() to print values in our browser. Console.log is just one method of console object.

In this article, we gonna use and see how each one works.

If you open the console in your browser and write ‘console’ you can see all methods inside of that.

  1. console.assert()

Log a message and stack trace to console if the first argument is false.

2. console.clear()

Clear the console

3. console.count()

Log the number of times this line has been called with a given label.

4. console.countReset()

Resets the value of the counter with the given label.

5. console.debug()

Outputs s message to the console with the log level debug.

6. console.dir()

Displays an interactive listing of the properties of a specified JavaScript object. This listing lets you use disclosure triangles to examine the contents of child objects.

7. console.dirxml()

Displays an XML/HTML element representationof the object if possible or the javaScript object view if it is not possible.

8. console.error()

Outputs an error message. You may use string substitution and additional arguments with this method.

9. console.exception()

An alias for error().

10. console.group()

Creates a new inline group, indenting all following output by another level.

11. console.groupCollapsed()

However, unlike group() this starts with the inline group collapsed requiring the use of a disclosure button to expand it.To move back out a level, call groupEnd().

12. console.groupEnd()

Exits the current inline group.

13. console.info()

Informative logging of information. You may use string substitution and additional arguments with this method.

14.console.log()

Print a message in screen.

15.console.profile()

Starts the browser’s buitl-in profiler (for example, the Firefox perfomance tool).

16. console.table()

Displays tabular data as a table.

17. console.time()

Starts a timer with a name specified as an input parameter. Up 10,000 simultaneous timers can run on given page.

18. console.timeEnd()

Stops the specified timer and logs the elapsed time in seconds since it started.

19. console.timeLog()

Logs the value of the specified timer to the console.

20. console.timeStamp()

Adds a marker to the browser’s Timeline or Waterfall tool.

21. console.trace()

Outputs a stack trace.

22.console.warn()

Outputs a warning message. You may use string substitution and additional arguments with this method.

As bonus let’s styling the console output and see the HTML tree structure into the console.

  • Styling console output
  • HTML tree structure into the console

Enjoy this article and share to your friends.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Mário Batalha
Mário Batalha

No responses yet