Chapter 17. 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 ...
Get JavaScript & jQuery: The Missing Manual, 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.