Chapter 2. Why JavaScript?
Table of contents
Buy the book
(Ad, please don’t block.)

Chapter 2. Why JavaScript?

There are many programming languages out there. Why should you use JavaScript? This chapter looks at seven aspects that are important when you are choosing a programming language and argues that JavaScript does well overall:

  1. Is it freely available?
  2. Is it an elegant programming language?
  3. Is it useful in practice?
  4. Does it have good tools, especially good integrated development environments (IDEs)?
  5. Is it fast enough for what you want to do?
  6. Is it widely used?
  7. Does it have a future?

Is JavaScript Elegant?

Yes and no. I’ve written fair amounts of code in several programming languages from different paradigms. Therefore, I’m well aware that JavaScript isn’t the pinnacle of elegance. However, it is a very flexible language, has a reasonably elegant core, and enables you to use a mixture of object-oriented programming and functional programming.

Language compatibility between JavaScript engines used to be a problem, but isn’t anymore, partly thanks to the test262 suite that checks engines for conformance to the ECMAScript specification. In contrast, browser and DOM differences are still a challenge. That’s why it is normally best to rely on frameworks for hiding those differences.

Is JavaScript Useful?

The most beautiful programming language in the world is useless unless it allows you to write the program that you need.

Other Technologies Complementing JavaScript

There are more technologies than just HTML5 that complement JavaScript and make the language more useful:

JavaScript has an abundance of libraries, which enable you to complete tasks ranging from parsing JavaScript (via Esprima) to processing and displaying PDF files (via PDF.js).
The Node.js platform lets you write server-side code and shell scripts (build tools, test runners, etc.).
JSON (JavaScript Object Notation, covered in Chapter 22)
JSON is a data format rooted in JavaScript that has become popular for exchanging data on the Web (e.g., the results of web services).
NoSQL databases (such as CouchDB and MongoDB)
These databases tightly integrate JSON and JavaScript.

Does JavaScript Have Good Tools?

JavaScript is getting better build tools (e.g., Grunt) and test tools (e.g., mocha). Node.js makes it possible to run these kinds of tools via a shell (and not only in the browser). One risk in this area is fragmentation, as we are progressively getting too many of these tools.

The JavaScript IDE space is still nascent, but it’s quickly growing up. The complexity and dynamism of web development make this space a fertile ground for innovation. Two open source examples are Brackets and Light Table.

Additionally, browsers are becoming increasingly capable development environments. Chrome, in particular, has made impressive progress recently. It will be interesting to see how much more IDEs and browsers will be integrated in the future.

Is JavaScript Fast Enough?

JavaScript engines have made tremendous progress, evolving from slow interpreters to fast just-in-time compilers. They are now fast enough for most applications. Furthermore, new ideas are already in development to make JavaScript fast enough for the remaining applications:

  • asm.js is a (very static) subset of JavaScript that runs fast on current engines, approximately 70% as fast as compiled C++. It can, for example, be used to implement performance-critical algorithmic parts of web applications. It has also been used to port C++-based games to the web platform.
  • ParallelJS parallelizes JavaScript code that uses the new array methods mapPar, filterPar, and reducePar (parallelizable versions of the existing array methods map, filter, and reduce). In order for parallelization to work, callbacks must be written in a special style; the main restriction is that you can’t mutate data that hasn’t been created inside the callbacks.

Is JavaScript Widely Used?

A language that is widely used normally has two benefits. First, such a language is better documented and supported. Second, more programmers know it, which is important whenever you need to hire someone or are looking for customers for a tool based on the language.

JavaScript is widely used and reaps both of the aforementioned benefits:

  • These days, documentation and support for JavaScript comes in all shapes and sizes: books, podcasts, blog posts, email newsletters, forums, and more. Chapter 33 points you toward important resources.
  • JavaScript developers are in great demand, but their ranks are also constantly increasing.

Does JavaScript Have a Future?

Several things indicate that JavaScript has a bright future:

  • The language is evolving steadily; ECMAScript 6 looks good.
  • There is much JavaScript-related innovation (e.g., the aforementioned asm.js and ParallelJS, Microsoft’s TypeScript, etc.).
  • The web platform of which JavaScript is an integral part is maturing rapidly.
  • JavaScript is supported by a broad coalition of companies—no single person or company controls it.


Considering the preceding list of what makes a language attractive, JavaScript is doing remarkably well. It certainly is not perfect, but at the moment, it is hard to beat—and things are only getting better.

Next: 3. The Nature of JavaScript