Eloquent JavaScript

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! 🙂

4 thoughts on “Eloquent JavaScript

  1. Pingback: Book: Eloquent JavaScript « chooru_code

  2. 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.

    Duuuuuuuuude! 😉

    I have been away from JS for a while now. But I’m really surprised if the book didn’t mention these standalone runtimes:

    1) Google’s V8 (http://code.google.com/p/v8/)
    2) Javascript has been part of the JDK for ages now (http://download.oracle.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html#jsengine)
    3) Mozilla’s long time runtime: http://www.mozilla.org/js/spidermonkey/

    With stuff like Node.js, server side Javascript is also increasing. I’m sure you’ll find decent enough tools. I don’t know if you’ve tried Aptana, WebStorm or Venkman. NetBeans also has good JS support apparently.

    Javascript programmers are all over the web 😛 Just look around on StackOverflow, Quora or proggit. You’ll find whatever help you need.

    • Pramod: This book is actually aimed at the newbie to programming (not just to JavaScript). So, it does not really get into the available compilers for JS. Instead the author allows the reader to try code in the sandbox he has built with his online book (which uses the browser’s JS interpreter).

      OTOH I would love to have a standalone JS compiler/interpreter, because I am that kind of a Luddite! 😀 Thanks for pointing out those runtimes, I will see which of those is good to play around with.

  3. Pingback: JavaScript: Standalone compiler or interpreter for Windows? - Technology

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: