O'Reilly logo

The Book of JavaScript, 2nd Edition by thau!

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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! ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required