Effective JavaScript

Author: David Herman
Publisher: Addison-Wesley
Pages: 240
ISBN: 978-0321812186
Audience: Intermediate JavaScript programmers
Rating: 5
Reviewer: Ian Elliot

JavaScript can be difficult to get right if you don't understand it. This book provides 68 specific examples of how you can get it wrong and how to get it right.
Is this the correct way to learn JavaScript?

The big problem with JavaScript is that so many programmers "pick it up" and don't spend the time they should learning it. Even if they do, most of the introductions treat the language as if it was a substandard version of Java or C++. It would be better if the language was taught correctly initially rather than having to patch up the misunderstandings at  a later date.

This is what this particular book attempts to do - put right the misunderstandings. What this means is that it isn't a beginner's book and it doesn't teach you JavaScript. You will only get something from this book if you have written enough JavaScript to have made most of the mistakes explained in this book. 

Of course if you are a JavaScript expert and have read other similar books or articles then you will already know most, if not all, of the problems and solutions outlined. In short there isn't anything new in this book, but it is well presented and explained.


The book starts off with a look at what JavaScript is and its relationship to ECMAScript. Don't expect any complete answers because the situation is a mess. The idea that JavaScript doesn't have integers is explained and then we look at semicolon insertion and the Unicode string problem. This is a bit of a random collection of simple items. 

Chapter 2 deals with scope and the problems of using a language that only supports function scope. Chapter 3 is about functions and mostly about the fact that functions are first class objects plus all of the nice extras that this provides. 

Chapter 4 is about the way objects work - the prototype idea in particular. This is one of the things that most programmers get worried about - but in fact prototype doesn't play a huge role in day-to-day JavaScript programming. When it does however you need to make sure you understand it. The only problem with this chapter is that if focuses down on the small details of how objects work without discussing the bigger picture. Not all JavaScript objects need or use constructors and hence not all objects need or use prototypes. However, matters of philosophy probably don't belong in this book. 


Chapter 5 explains the difference between a JavaScript Array and a dictionary object - which is just an object used as a dictionary. The distinction between the two types of data structure should be fairly clear but it is surprising how often even experienced programmers pick the wrong one to use. 

Chapter 6 marks a change of subject matter. It is about library and API design and is more about best practices rather than dangerous bit of JavaScript. It covers ideas like the use of an options object to simplify an API. 

Chapter 7 is on concurrency which might surprise you if you know that JavaScript is essentially single-threaded, but this is the point. It is really about asynchronous programming and how not to block the UI thread. It covers callbacks, using recursion in place of loops and it eventually gets to promises but only in a theoretical sort of way - i.e. it doesn't specify a particular implementation of promises or how to create an asynchronous function that returns a promise. It doesn't deal with worker threads which are arguably not part of JavaScript but HTML.

The book is a good read. Even if you know some of the problems or even all of the problems it outlines then you will still most probably enjoy reading it. It introduces the problem by showing you an example of how it shouldn't be done and then by giving you the solution. I couldn't help but keep on thinking that much of what was being explained would be more obvious to the average JavaScript programmer if the language was taught or explained properly in the first place. For example if you really take to heart the idea that everything is an object then many of the behaviors which are claimed to be surprising are in fact perfectly obvious and logical. And most of all stopping trying to force JavaScript's object-oriented facilities into the classical class based strongly typed hierarchy would also make things seem much more logical. JavaScript is a unique, powerful and fun language and it deserves to be treated right. 

However, if you simply want to patch up your existing knowledge of JavaScript to avoid making mistakes and to adopt best practices then this book will help. Did I mention it is also a fun read? Highly recommended. 

Further Reading

Treat JavaScript right!


More recommended JavaScript books


Expert Performance Indexing in Azure SQL and SQL Server 2022

Author: Edward Pollack & Jason Strate
Publisher: Apress
Pages: 659
ISBN: 9781484292143
Print: 1484292146
Kindle: B0BSWH65ST
Audience: DBAs & SQL devs
Rating: 4 or 1 (see review)
Reviewer: Ian Stirk 

This book discusses indexes, a primary means of improving performance in SQL Server, how does  [ ... ]

Software Development Pearls

Author: Karl Wiegers
Publisher: Addison-Wesley Professional
Pages: 336
ISBN: 978-0137487776
Print: 0137487770
Kindle: B09BF6CS9T
Audience: General developers
Rating: 2
Reviewer: Ian Elliot
Who can resist a good pearl or two?

More Reviews


Last Updated ( Sunday, 05 May 2013 )