Boost your JavaScript Debugging Skills With These Console Tricks

JavaScript gives us plenty of tools to debug our code

Photo by Tracy Adams on Unsplash

The cookie-cutter way of debugging JavaScript code is to simply output the results via the console.log method. While it works, it’s not the most optimal way of doing things. If there are better ways out there, why not explore them?

“Hello from the console”

The console object provides access to the browser's debugging console. You can use the console object only if run your JavaScript code on the browser, i.e client-side code, not server-side code. How it works varies from browser to browser, but there is a de facto set of features that are typically provided. The best part of the debugging statements is they work with all libraries and frameworks since they’re baked inside the core language.

The most basic use case for the console.log is to show the output of the code. Take the following code:

It logs the name passed to the sayHello function.

Outputting the name passed to the function