Debugging with JavaScript console
2 min readDebugging is an essential part of programming. As a Developer I spent some of my time fixing bugs and problems.
Let's cover and share some tips and tricks for debugging with the JavaScript console
object. Taking a look at the methods to get an in-depth knowledge of the debug process.
Assertions
console.assert()
Use console.assert()
to check if evaluated expression is false. You must pass a boolean assertion to the .assert()
method.
Logging
There are a lot of methods to log information and values to the console.
console.trace()
Prints a stack trace. This is useful to see where a method call starts and his cycle.
console.table()
Displays Object and Array data into a friendly tabular format.
console.log()
console.error()
console.warn()
Displays an information, warning or error message to the console.
Timers
console.time()
console.timeEnd()
Starts a timer with an associated label to track how long a process takes to complete.
Functions
monitor()
Use the monitor()
method to track function calls. Returns the name of the function called and the arguments.
Events
monitorEvents()
Use the monitorEvents()
method to listen for events on a specified object.
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
Enjoyed the article? 😍