Scato Eggen
February 26, 2016
If you want to know what JavaScript really is, you have to look beyond just the language. In contrast to PHP, there are several platforms that it runs on. And then there’s the ecosystem, which is nothing like the one PHP has.
The language
JavaScript was created at Netscape in 1995 by Brendan Eich. Later, the language was standardized under the name ECMAScript. A number of small changes were made in the specification, until the 4th edition that was proposed in 2007. It proposed pretty much an overhaul of the language and was abandoned because it was improbable that browser vendors would implement the entire specification.
After that, work on ECMAScript proceeded at a lower pace. Instead of taking a big bang approach, a steady evolution was set in motion. Transpilers (compilers that take modern ECMAScript and translate it to an older version of ECMAScript that browsers understand) were introduced, which meant that developers could start using new language features without having to wait for browser vendors to implement them.
On top of the language features designed by the standards committee, the community introduced its own language features. An important one is JSX, which lets you use HTML inside JavaScript code. JSX was introduced by Facebook to support React. Later, other implementations of the same technique emerged.
Other languages have been created that compile to JavaScript. CoffeeScript was one of the first, and is aimed at exposing the good parts of JavaScript without the “awkward” Java-like syntax. Other examples of languages that compile to JavaScript are: ClojureScript, TypeScript and Elm.
Last but not least, there is asm.js. This subset of JavaScript was specifically designed for optimizability. Emscripten is a transpiler that takes C or C++ code and translates it to asm.js. What this means is that you can play Unreal 3 in Firefox without any special plugins whatsoever. According to Scott Hanselman, you could argue that JavaScript is an operating system.
The platforms
The first implementation of JavaScript in 1995 was shipped with Netscape Navigator 2.0. Microsoft Internet Explorer followed in 1997 with JScript. JavaScript was applied outside of the browser, but it was only when Node came out in 2009 that JavaScript became really popular.
JavaScript is not only used in browsers and Node, but in mobile apps as well. Cordova lets you build hybrid apps (which have an HTML/CSS user interface, but which can access things like the camera through a native API). Titanium has its own user interface toolkit named Alloy. And then there’s this new breed of apps called “Native JavaScript Apps”. React Native is a framework that lets you build such an app. Instead of the DOM, or some other generic user interface toolkit, React Native uses the toolkit of the OS directly (Cocoa for iOS, Lollipop for Android).
Another exciting development is Electron. This lets you build hybrid apps for desktop. The user interface is built in HTML/CSS, while file and network I/O is done through Node APIs.
With all these platforms, the need for JavaScript libraries that run everywhere is greater than ever. This has caused the emergence of a movement called “Universal JavaScript”.
Basically, a platform consists of three parts, the engine being only one part of it: the infrastructure (Chrome, Node, Cordova, Electron, etc.) the UI (DOM, Alloy, Cocoa, etc.) the engine (e.g. V8)
The ecosystem
DynAPI is possibly one of the first JavaScript libraries. I’m not sure when the project was started, but it was definitely before 1999. The main reason to use DynAPI was to work around the many cross-browser incompatibilities at the time.
This has been the main focus of most JavaScript libraries that came after, until jQuery in 2006. The API that jQuery provided was a lot nicer to work with than the DOM API. Also, jQuery made heavy use of the functional aspects of the language. With the implementation of querySelector() and querySelectorAll() by all major browsers, and the CSS3 selectors that came with it, jQuery lost its central place in the ecosystem.
Recently, we saw the rise of the MV* frameworks. The three that came out on top were: Backbone, Angular and Ember. Just like the PHP community is subdivided by developers that use Zend Framework, Symfony and Laravel, these MV* frameworks caused subcommunities to form.
Node has made a huge impact on the JavaScript community as well. Although Node has its own community, its package manager (npm) has influenced the front-end community to set up Bower. As a command line runtime, Node also caused a staggering growth of tooling for front-end development.
All in all, the JavaScript community is pretty scattered. If you look at conferences that include JavaScript, you end up at conferences about:
- JavaScript
- frameworks like React, Ember and Angular
- frameworks like PhoneGap (Cordova)
- Node
- front-end and UX
- web technology and full stack
- languages like CSS and HTML5
- languages like PHP
There are subcommunities for specific frameworks, and broad communities like web technology. This is the same for the PHP community. But not everyone in the JavaScript community comes from the same background. Some are front-end developers, often with a background in design as well. Then there are Node developers, probably coming from some other server-side technology. Finally, there’s the full stack developers for whom JavaScript is but a part of their work.
The future
Will JavaScript render all other technologies obsolete? Probably not.
In 2007, Jeff Atwood proposed the following law:
any application that can be written in JavaScript, will eventually be written in JavaScript
It seems he was right. Although the reverse is probably true as well:
developers will always write applications in languages other than JavaScript, if only because they can
Nobody knows exactly what the future of PHP looks like. Lots of startups are choosing JavaScript because of the freedom it brings, but many of those startups are discovering the downsides of a technology that is not as mature as Java, or PHP to a lesser extent. Before JavaScript, startups used to choose PHP instead of Java, for exactly the same reason.
The PHP community has learned from the Java community (among others) and the JavaScript community is learning from the PHP community (among others) in turn. Initiatives like TypeScript help make the gap between PHP and JavaScript smaller bit by bit, so it’s not unthinkable that TypeScript will end up where PHP is today.