Thursday, May 29, 2025
# Debugging JavaScript
You can print values to the browser console or node.js console using console.log
. But did you know you can save yourself a bunch of typing by using debugger
instead?
debugger;
When evaluation reaches this statement, execution of your JavaScript will pause and you can inspect the state of your application.
Instead of console.log
ing everything in sight, we can just mouse over a variable to see its type and value.
Browsers support debugger
statements out of the box, as long as the console or dev tools are already open. If you're using node.js you'll need to use the node inspect
command. Your IDE may also support native debugging. In environments where debugger
is not supported, the statement is simply ignored.
Shout out to my friend Max, who taught me about debugger
during a debugging session.