Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Eloquent JavaScript

📅 2011-Apr-20 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ book, javascript ⬩ 📚 Archive


Once upon a time, every PC had a BASIC interpreter on it and an entire generation of programmers was spawned due to kids playing around with BASIC. My first experience with programming was in high school and it was with BASIC too! In the school library I discovered books written by David H. Ahl and others which had listings of simple BASIC games. Since those books were not lent out, I would write down the code listings onto paper and then type them in during computer class. The code I copied would inevitably have errors and it took a while to find and fix them. Much joy was had when the code executed and a simple game materialized on the screen.

Marijn Haverbeke, the author of Eloquent JavaScript fervently believes that JavaScript is the BASIC of today. It is indeed true, since every computing device today has a browser with a JavaScript interpreter cranking beneath it. With this motivation, Marijn has written this as a book for anyone who wants to learn programming.

I picked up this book to see what lay behind this language which is all pervasive and yet highly misunderstood and frowned upon. JavaScript was pushed out through the backdoor into the Netscape Navigator browser at the same time Sun Microsystems launched Java with much fanfare onto the world. Other than the 4 letters they both share, there is absolutely nothing in common between these languages! The book reveals that JavaScript is a badly designed, but highly powerful dynamically typed functional programming language hiding in C-like syntax! 😁

Writing some JavaScript code is easy, but writing good code in it is hard. This is not entirely the programmer’s fault, since the language has some seriously confusing features. For example, there are no classes in JavaScript, instead objects are created from constructors which have an underlying prototype. Properties and methods can be appended at will to both the objects and their prototypes. The book tries quite well to demystify such difficult concepts, but I still came away quite confused.

Functions are first class types in JavaScript, I was totally shocked to realize that we have a functional programming language throbbing underneath all our browsers! It was refreshing to see this introductory book treat functional programming as de riguer in JavaScript. All code examples in the book create and pass around functions whenever appropriate. I am still not familiar with functional programming, but this book gave me the most gentle introduction yet to this paradigm.

Programming the browser is not touched until the last 4 chapters. These chapters run through quickly showing examples of how to use JavaScript to read and modify the various web page elements. These are accessible through the Document Object Model (DOM) that the browser exposes to JavaScript. This too was quite an eye opener since I have not done any web programming other than some Perl and CGI in a former life.

Eloquent JavaScript is a good introduction to the language that can be easily finished over a weekend. The book is also available online here, where all its code examples can be edited and executed right inside the browser. I found most code examples useful, except for the grand Game of Life (Terrarium) example which is used throughout the chapter on Object-Oriented Programming. That example was just too big and was not instructive.

The book does enough to stoke the reader’s interest to program in JavaScript. I am looking around the JavaScript tool landscape and am pretty disappointed by the lack of standalone JavaScript interpreters or compilers, editors with code completion and IDEs with debugging capability. Easy availability of such tools and the ability to run standalone JavaScript programs would do wonders for this language! 😊

Rating: 3/4

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧