Beautiful JavaScript

Editor:  Anton Kovalyov
Publisher: O'Reilly
ISBN: 978-1449370756
Kindle: B013VQ7N3G
Audience: Intermediate JavaScript Programmers
Rating: 4.5
Reviewer: Ian Elliot

Can JavaScript be beautiful? There are a lot of programmers who don't think so. 

This is a book that aims to get you thinking about JavaScript as more than a scripting language or simply a failed version of Java or C++. With the subtitle "Leading Programmers Explain How They Think", it is a collection of essays by different authors and each one treats their subject in a very different way. There is nothing uniform about this book and what each of the authors attempts to convey is idiosyncratic in content and style. 

The first essay is perhaps the toughest in the book if you are a JavaScript beginner. Beautiful Mixins attempts to explain a clever alternative approach to creating a mixin. The problem is that this first essay assumes a great deal of sophistication on the part of the reader as it discusses the philosophy and problems with JavaScript's prototype system. If you are not good at JavaScript you might well wonder what the discussion is all about. If you are then you will probably find yourself agreeing with the author. 

The next essay is about using eval for domain specific languages. The example is a template compiler. Eval is a difficult topic because it is generally regarded as a terrible thing - it stops JavaScript being optimized and it is a security risk. However it also happens to be a very powerful feature that only dynamic languages can easily provide. So it makes sense not to ignore it and to find out as much as you can about it. 

The third essay is the first of a number that are "fanciful". How to Draw a Bunny is a strange account of the range of expressions available to a JavaScript programmer. It argues that, while it might not be the best production code, clever idiomatic JavaScript might well be beautiful JavaScript. Of course, if you don't know enough JavaScript, you might not understand the examples.

The essays seem to fall into one of these two categories. Either the author has taken a specific aspect or task in JavaScript and used it to illustrate a wider point; or some philosophical point is illustrated by examples. For example, Too Much Rope takes the view that clarity is the most important part of coding and you should avoid the clever and perhaps beautiful ways of doing things.   

Next we have an essay on constructors and object factories - nothing new but the average JavaScript programmer will probably not have met the ideas before. One World, One Language is a strange little essay on the joys of JavaScript as an educational language - the one to teach. Just as strange is the inclusion of Math Expression Parser and Evaluator. It shows how to do simple language processing - lexer, parser and tree walker in JavaScript. Interesting but not really about the beauty of JavaScript. 

Evolution is an account of the use of frameworks - Backbone in particular and how this alters the way JavaScript is used. Next we have two tutorials, Error handling and The Node.js Event Loop. Again both interesting but not really about the beauty of JavaScript. 

 The collection gets back on topic with the essay JavaScript Is, summed  up by - dynamic, static, functional, everything. Next, Coding Beyond Logic is very, very strange as it is a riff on the idea of a Quine - a program that when executed outputs itself. What this has to do with JavaScript in particular, or beauty?

The next two essays are much more what the entire book should be. JavaScript is Cutieful is a close examination of one line of idiomatic JavaScript code that will challenge your grip on the world:


This creates a 10 element array initialized to 0,1,2,3,,9. 

Now is this beautiful? 

I think you have to answer yes, but this isn't code you necessarily want to include in a production program - or is it?

The penultimate essay is a discussion of JavaScript as a functional language. Of course JavaScript isn't a hardline functional language and as such it gets criticism in this area as well as everything else. However, you might well write better code by taking a functional approach and try to enforce immutability as much as possible. 

The final essay, Progress, discusses the use of the ES6 class construct compared to alternative ways of doing the same job. This argues against the proposition that classical JavaScript is beautiful because it argues that JavaScript is more beautiful if we convert it into a different language - one that does inheritance. 

Overall this is a very mixed bag of essays. You do get the feeling that not everyone asked to contribute actually believes that JavaScript is a beautiful language. There is no coherent view or approach to explaining what makes JavaScript special. For me about four of the essays got it right, but you might well find that more or even fewer hit the spot. 

If you are, or on your way to becoming, a sophisticated JavaScript programmer you will probably find something to amuse or interest you.  

We have reviews of over 90 JavaScript titles. 

For recommendations see:

JavaScript Beginners Book Choice 
Building A JavaScript Library


Other O'Reilly "Beautiful" titles

Beautiful Architecture Rated 4 out of 5 by Mike James

Beautiful Code Rated 4.5 out of 5 by Mike James

Beautiful Data Rated 3 out of 5 by Mike James

Beautiful Security Rated 3 out of 5 by Harry Fairhead

Beautiful Teams Rated 4.5 out of 5 by Mike James

Beautiful Testing Rated 3 out of 5 by Mike James

Beautiful Visualization Rated 4 out of 5 by David Conrad


To keep up with our coverage of books for programmers, follow @bookwatchiprog on Twitter or subscribe to I Programmer's Books RSS feed for each day's new addition to Book Watch and for new reviews.






Last Updated ( Saturday, 08 September 2018 )