Chapter 11. Browser Tools
As a web developer, the browser is the window through which the world accesses your creations. It also provides helpful tooling for developing and testing your sites. It is a worthwhile investment to learn how to use your browserâs development tools so that you may better and more easily debug your code. In this chapter weâll cover several useful features for debugging, profiling, and analyzing JavaScript.
For simplicity, all of the examples in this book will make use of Google Chromeâs Developer Tools (DevTools). At the time of writing, Chromeâs usage makes up over 65% of the global browser share. Most other browsers offer similar functionality. Mozillaâs Firefox Developer Edition is an excellent alternative with useful developer features.
Debugging JavaScript
Problem
You need to know the value of a variable at a specific point in your JavaScript codeâs execution.
Solution
Use a breakpoint to inspect code values and types. When setting a breakpoint, the browserâs debugger will stop at the point of the breakpointâs code execution and display each of the current values in scope. It is then possible to step through the code or allow the JavaScript to finish executing. Figure 11-1 shows a screenshot of code paused on a breakpoint.
To set a breakpoint on a specific ...
Get JavaScript Cookbook, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.