Finding Bugs

Much of the debugging process involves discovering where the bug is in the first place. Unfortunately, finding the little pests isn't always easy.

You can look for bugs in lots of different ways. This section covers some of your major options, from writing alerts into your code to using your browser's bug detector and other debugging tools.

Printing Variables with alert() Statements

The most tried-and-true debugging method is to use alert() statements to print out what's going on in your script.

Figure 18-1 lists two functions. In one, if you enter random names in the prompt boxes, you'll see the greeting Ahoy, polloi! If you enter Dave in the first prompt box and Thau in the second one, you're supposed to get the message Howdy, partner! ...

Get The Book of JavaScript, 2nd 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.