Chapter 11
Ten JavaScript Debugging Strategies
IN THIS CHAPTER
Debugging with the Console, breakpoints, and other dev power tools
Writing code to make it easier to debug
Craftily debugging with comments
Given any nontrivial JavaScript code, it’s a rare (probably nonexistent!) script that runs perfectly the first (or even the tenth!) time. Script bugs happen to even the most experienced developers, so having errors in your code does not mean you’re a failure as a coder! All it means is that you’re a coder.
But when bugs get into your code, you’ll want to exterminate them as quickly as you can. This chapter provides you with ten debugging strategies that can help.
Get Thee to Your Dev Tools
All web page debugging begins with a visit to your web browser development tools. In every browser, the quickest way to open the dev tools is to right-click a page element and then click Inspect. You can also press Ctrl+Shift+I (Windows) or Option⌘ +I (macOS).
The Console Is Your Best Debugging Friend
In your code, you can see the current value of a variable or object property by outputting that value to the dev tools Console tab:
console.log(output);
Replace output with the expression you ...