๐Ÿ”ฅJS Debugging Tips

๐Ÿ”ฅJS Debugging Tips

ยท

1 min read

Knowing your tools can make all the difference when it comes to getting things done. Despite JavaScript's reputation for being difficult to debug, if you have a few tricks up your sleeve, errors and problems will take less time to fix.

1.Console.time() and timeEnd(): The console object has time() and timeEnd() methods that help with analysing performance of pieces of your code.

image.png

2.Console.trace(): console.trace() to get a quick and easy stack trace to better understand code execution flow.

image.png

3.Console.table(): Use console.table instead of console.log to get a nicer formatted output ๐ŸŽ‰

image.png

4.Console.assert(): Conditional logging ( without wrapping your logs with if-else) ๐Ÿ˜Ž You can use console.assert(condition, msg) to log something when the condition is falsy.

image.png

4.Bonus Tip: Tired of having to write clear() or console.clear() when debugging in the browser console?

Just define a getter for clear on the global object that does it for you. Then you can type clear just like you would in the terminal!!!

image.png

ย