Secrets of the JavaScript Ninja: Chapter 2 Review

Arming with Testing and Debugging

JavaScript development has come a long way since I started, back when Netscape and AOL were king. The days of sprinkling alert statements into your code is long past (and thank the gods for that).

Mr. Resig does make a brief mention of the old ways, with the same sentiment, and goes on to mention the basic tools we have for debugging today. All of the major browsers have excellent tools for developers built into them now. Like me, he thanks the developers of Firebug for starting us down this road. They set the bar for the browser makers to reach, and continue to do so.

Debugging essentially breaks into three areas: logging, breakpoints, and inspection.


The book suggests a possible unified logging function to support all browsers (handling the different methods Firefox/Webkit/IE and Opera use, and falling back to actual alerts if needed).


These are consistent in browsers, and good logging tells you where you need to put them. Further, these days you can set conditions on your breakpoints so they’ll only stop when you need them to.


The book doesn’t mention inspection, which I consider at least as important as logging and breakpoints. Being able to inspect the rendered state of a DOM element or explore the structure of an object in JavaScript is invaluable. But inspection is mostly to benefit the DOM, which is outside the scope of the book.


Resig spends most of the chapter making the case for Unit Tests in JavaScript. There are multiple unit testing frameworks available for free, and many are quite good. I disagree about the universal importance of unit testing, but it’s very important to Resig. It’s also very useful for the study of JavaScript, to test how things work.

What I Learned In This Chapter:

It’s hard to be in the business this long without picking up the information in this chapter, but I still managed to hear about a testing framework or two I didn’t know about.