O'Reilly logo

JavaScript & jQuery: The Missing Manual, 2nd Edition by David Sawyer McFarland

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

Chapter 15. Troubleshooting and Debugging

Everybody makes mistakes, but in JavaScript, mistakes can keep your programs from running correctly—or at all. When you first start out with JavaScript, you’ll probably make a lot of mistakes. Trying to figure out why a script isn’t behaving the way it should can be frustrating, but it’s all a part of programming. Fortunately, with experience and practice, you’ll be able to figure out why an error has occurred and how to fix it.

This chapter describes some of the most common programming mistakes, and, more importantly teaches you how to diagnose problems in your scripts—debug them, as programmers say. In addition, the tutorial will take you step-by-step through debugging a problematic script.

Top JavaScript Programming Mistakes

There are countless ways a program can go wrong, from simple typos to more subtle errors that only pop up every now and again. However, there are a handful of mistakes that routinely plague beginning (and even advanced) JavaScript programmers. Go over the list in this section, and keep it in the back of your mind when programming. You’ll probably find that knowing these common mistakes makes it a lot easier to identify and fix problems in your own programs.

Non-Closed Pairs

As you’ve noticed, JavaScript is filled with endless parentheses, braces, semicolons, quotation marks, and other punctuation. Due to the finicky nature of computers, leaving out a single punctuation mark can stop a program dead in its tracks. One of ...

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