Debugging in JavaScript with the Console API

Debugging in JavaScript with the Console API
Average rating: 0
(0 votes)

Believe it or not, but we know a lot of secrets about how to improve your Javascript skills. For example, do you want to make your logs better? If so, let’s talk about debugging in JavaScript with the Console API. The specifics of how it works varies from browser to browser, but there are some features that are typically provided. We are going to share them with you.

Console object can be accessed from any global object. Window on browsing scopes and WorkerGlobalScope as specific variants in workers via the property console. It’s exposed as Window.console, and can be referenced as simply console.

  • The most useful feature of the console is logging of text and other data. There are four categories of output you can generate, using the console.log()console.info()console.warn(), and console.error() methods. Each of these results in output styled differently in the log, and you can use the filtering controls provided by your browser.
  • In order to calculate the duration of a specific operation, there is a console object. To start a timer,  you can call the console.time() method, giving it a name as the only parameter. To stop the timer, and to get the elapsed time in milliseconds, just call the console.timeEnd() method
  • The console object also supports outputting a stack trace. This will show you the call path taken to reach the point at which you call console.trace().
  • In case you have so many logs that you don’t know how many times given parts of the code have been executed, there’s an API for that. The console.count() method counts how many times it’s been called.

Let it be debugged! There are many more thing to learn, and you can find them here.

And we are happy to announce that Javascript Specification homepage was eventually written!

Rate this article, if you like it

Thanks! You’ve rated this material!

Got a project? Let's discuss it!

*By submitting this form you agree with our Privacy Policy.

Mailing & Legal Address

Syndicode Inc. 340 S Lemon Ave #3299, Walnut CA, 91789, USA

Visiting & Headquarters address
Kyiv Sofiivska 1/2a, 01001, Kyiv, Ukraine
Dnipro Hlinky 2, of. 1003, 49000, Dnipro, Ukraine
Email info@syndicode.com
Phone (+1) 9035021111