The Book of JavaScript, 2nd Edition


This book review was published by Slashdot, 2007-03-07.

Book of JavaScript, 2nd Edition

Developers of websites, whether professional programmers or Web hobbyists, are oftentimes impressed by the more advanced functionality that can be achieved on a Web page using JavaScript. Yet these personal discoveries of JavaScript's power do not always motivate the developers to implement similar functionality on their own sites — partly because most of those custom-built JavaScript functions are cryptic, and make no attempt to show how the developer would customize the code for their own use. The majority of JavaScript books are of limited help in this regard, because they focus on the language details, illustrated only with code snippets. Many readers would benefit more from instruction via working examples, which is the approach used by The Book of JavaScript.

The book was written by David Thau, a.k.a. "thau!", a veteran of the Internet and computer programming — especially JavaScript, which he has taught to countless other programmers, through this book, as well as numerous courses, conference presentations, and the tutorials he has written for Webmonkey.

Published by No Starch Press under the ISBN 978-1593271060, the second edition of The Book of JavaScript appeared on 15 December 2006. The publisher maintains a Web page for the book, where visitors can find an online copy of the book's table of contents, excerpts from reader reviews, links for purchasing the paper and electronic versions of the book, a sample chapter ("Chapter 2: Using Variables and Built-In Functions to Update Your Web Pages Automatically") as a PDF file, the errata discovered by the author and readers (several reported so far), and a link to the author's companion site.

Unlike some books' companion sites, this one is worth a visit, and not just to see a working example of the tip box described in chapter 8, which is used to show how to create an array. Thau's site has links for viewing, running, and downloading all of the sample code in the book's figures. In addition, the visitor can obtain copies of the book's JavaScript libraries, for doing cookies, form validation, and plug-in detection. There are links for viewing and downloading the three sample websites. However, in his AntWeb site, at least as of this writing, none of the images are showing up on his homepage. Another problem, of much less importance, is the strange behavior of the "Websites" and "Freeware" options on his "Chapters" drop-down list box. Choosing either one takes the visitor to his "Websites" page, but always displays "Freeware" in the drop-down. It is hard to imagine that this behavior is intentional.

The book's material spans 528 pages, most of which is found in 18 chapters, covering a variety of topics: an overview of JavaScript's capabilities, alternatives, and limitations, among other less technical issues; variables and built-in functions; browser detection and simple control flow; rollovers, events, images, and the "document" object; window manipulation and properties; creating your own JavaScript functions; Web forms; arrays and iteration; timing events; frames and image maps; handling form input and strings; cookies; dynamic HTML, CSS, and DOM; AJAX basics; XML; server-side AJAX; a sample application (an online to-do list); and debugging JavaScript and AJAX. The book also offers four appendices: answers to chapter assignments; online resources (tutorials, sample code, AJAX sites, and AJAX frameworks); a complete reference to JavaScript's objects and functions; the code for the book's two longest applications, namely, the Italian translator and the to-do list.

This second edition serves as a follow-up to the well-regarded first edition that came out seven years earlier. Both the book and the language itself have clearly withstood the test of time. There are several reasons for the popularity of that first edition: It taught the language and its capabilities largely through the use of complete JavaScript functions, each of which served as an illustrative example of not just the elements and rules of the language, but also straightforward ways of accomplishing common tasks in JavaScript. After all, looking at sample code is how most programmers prefer to learn or verify how a language works.

The book assumed no prior knowledge of JavaScript or any other computer language, on the part of the reader. This characteristic not only set it apart from the large number of other JavaScript titles published at that time, but it made the book more attractive to people new to programming in general and Web programming in particular. Such readers might also favor this book over others because of the author's approachable writing style, in which he fully explains topics in a leisurely manner, without the terseness seen in most programming language books. This is not to say that brevity in technical works is ever a mistake per se; the busy professional programmer wants to find answers as quickly as possible. But such brevity can quickly prove frustrating to non-techies, who lack the background for understanding terse explanations and for knowing where they can turn for clarification.

All of these laudable attributes of the first edition have been carried over into this latest edition. The primary change found in this second edition, is the coverage of AJAX (asynchronous JavaScript combined with XML). Even though the additional material substantially increases the length of the book, by 124 pages, the end result is still far from unwieldy — mostly due to several factors: The book's table of contents, along with the index, are detailed enough to make it relatively easy to find a particular topic in the book, assuming that it is included. The subsection listings in the table of contents, like good source code, make liberal use of whitespace for readability. In the text itself, coloring the headings and note numbers blue make them stand out.

Aside from the aforesaid problems with the book's companion site, there are a few other areas for improvement: It was noted earlier that the last appendix contains the sample code from chapters 15 and 17. The author states that these code listings were located in an appendix, rather than the chapters themselves, because they are too long. Actually, they comprise only a dozen pages, which would have been better located in the chapters where the reader expects to see them, and where they would be close at hand for referencing. The first listing is only two pages long, and definitely should be located in chapter 15. Even for the second listing, if the author is concerned about readers getting frustrated flipping through the 10 pages to find the continuation of the chapter's discussion, a simple note at the beginning of that code, as to what page the discussion is resumed, would be sufficient.

Some fundamental language elements of JavaScript are introduced fairly late in the book. For instance, it is noted above that an explanation as to how to create an array — an essential concept in just about any procedural language — is not found until the eighth chapter, on page 134. This is more than one third of the way into the book's 18 chapters. On the other hand, given that the author has chosen to present these language concepts, for the most part, only when needed and when describing the sample code, this later introduction of some key concepts might not prove much of a problem to most readers. However, this is a case in which the completeness and accuracy of the book's index, are even more critical than usual. In this regard, the book does not fail the reader, as the index appears to provide enough coverage.

The formatting of the code throughout the text is not entirely consistent, as evidenced by some open braces appearing on their own lines, thus wasting space, and in other cases on the same line as the preceding parenthesized expression, though separated by a pointlessly large number of spaces. Code level blocks are indented two or four spaces, seemingly at random. Continuation lines are indented exactly the same; they would be more clear if they had double the number of spaces as code level blocks. Of more importance to the reader attempting to figure out what code is serving what purpose, there are far too many large chunks of code lacking any comments, which are needed, since much of the code is not self-describing. In most of the functions, the only comment lines are those for hiding the JavaScript from outdated browsers — a practice that should have been phased out in this latest edition.

Any experienced programmer who needs a complete JavaScript reference book, or a book that covers all the language's elements in fine detail, would be best served by choosing a different book from this one. On the other hand, once they had secured such a book, they would likely find David Thau's contribution an enjoyable source of ideas on what can be done using JavaScript capabilities. For anyone who wishes to learn JavaScript in a practical and relaxed way, by reading clearly explained sample projects and their code, should be well pleased with The Book of JavaScript.

Copyright © 2007 Michael J. Ross. All rights reserved.

This book is available on Amazon

Content topics: