JavaScript

Like many programmers, I’ve been using JavaScript for years, without really understanding everything about it. Recently I’ve been working on a project which is exclusively JavaScript, which is to say exclusively browser DOM manipulation via JavaScript, so I’ve been doing as much learning as possible.

First, the thing most worth knowing is that browser DOM APIs are NOT synonymous with JavaScript.  As Douglas Crockford says: “The API of the browser, the Document Object Model is quite awful, and JavaScript is unfairly blamed”.  Once JavaScript the language is separated with the way it interacts with the browser, one can be a little more objective about the language itself.  To that end, the highest recommendation I can give is to Crockford’s “JavaScript: The Good Parts” book.  It is an excellent exposition on the most useful and reliable subset of JavaScript.  Crockford explains that there are many average and poor parts of JavaScript, but that used properly and in a restricted way, it is a versatile and practical language.

Other excellent resources for understanding the JavaScript way of doing things are, particularly in the context of the browser:

  • A detailed talk on why the DOM causes so many headaches by the founder of the jQuery project, John Resig: The DOM is a Mess
  • Douglas Crockford's "Theory of the DOM" talk - parts 1, 2, 3

As Crockford mentions in his book,  most JavaScript references are not so useful, because they don’t differentiate between the bad parts and the good parts of the language, instead leaving them for you to figure out.  Nevertheless, it is probably worthwhile having a JavaScript reference, and O’Reilly’s guide by David Flanagan is probably a good start.  I’ve also got good mileage from Accelerated DOM Scripting with Ajax, APIs, and Libraries, which covers modern JavaScript in the browser reasonably well.

JavaScript can be quite neat, though it wouldn’t be a first choice for me unless it was necessary (essentially, if I was working on the client side, in a web browser).  I certainly wouldn’t use it server side for anything, though there’s plenty of effort in that area.

Another area gaining steam is Test-Driven-Development of JavaScript.  I’ve been using JsUnitTest, but there are a number of libraries out there, each with quirks of syntax and implementation.  JsUnitTest works well for me for the moment.