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.

Banner

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!

Banner

More recommended JavaScript books

Banner


Learn dbatools in a Month of Lunches

Author: Chrissy LeMaire et al
Publisher: Manning
Pages: 400
ISBN: 978-1617296703
Print: 1617296708
Kindle: B0B39PCHL8
Audience: SQL Server DBAs
Rating: 5
Reviewer: Ian Stirk 

This book aims to make it easier to manage your SQL Server estate, how does it fare? 



Administering Relational Databases on Microsoft Azure

Author: Prashanth Jayaram et al
Publisher: Independent
Pages: 622
ISBN: 979-8706128029
Print: B08Y4LBTP4
Kindle: B08XZQJHMK
Audience: Azure DBAs
Rating: 2 or 4 (see review for details)
Reviewer: Ian Stirk

This book aims to help you pass the Azure Relational Database exam DP-300, how does it fare?


More Reviews

 

Last Updated ( Sunday, 05 May 2013 )