The JavaScript Programming Language
With more than 600,000 JavaScript libraries and frameworks available and at least 3 billion downloads per week of the same, as well as more and more big companies converting their backends from other technologies to it, JavaScript adoption worldwide is simply skyrocketing. Let's see together why, and what, if ever, could arrest this process
Introduction
JavaScript is a computer programming language first appeared on the scene 29 years ago (on December 4, 1995). It is an interpreted, high-level, general-purpose, dynamically, weakly typed, object-oriented, imperative, functional and procedural programming language with automatic memory management whose relationship with Java is almost identical to its one with C#, that means almost none, a part from the word java that the two languages share.
JavaScript has been invented by Brendan Eich, at the time working for Netscape Communications, which recruited him with the goal to have a scripting programming language embedded into its Netscape Navigator browser. Since then JavaScript has been used as a scripting language in other applications and development environments by many organizations, but its use in the browser, as a front-end technology to assist in the visual representation and animation of graphical elements in the beginning, and to allow the development of complete client-side applications that run in the browser later, has become an industry standard at the point that still today JavaScript is the only programming language supported by any internet browser. The language is also increasingly used for server-side development. While a server-side version of the language was already released with Netscape Enterprise Server soon after its first release for browsers, only in recent years, with Node.js and the more performant JavaScript execution environments available these days, JavaScript adoption on the server-side has dramatically risen.
Today JavaScript is one of the most used programming languages in the world, if not the most used. In fact not only JavaScript is employed to develop software, it's also highly targeted as the final result of transpilations from other languages, none of which can be directly executed in the browser. This makes JavaScript the new Lingua Franca of the front-end software development industry.
First glance at the code
Example: The classic "Hello world" program written in JavaScript:
Main features of JavaScript
Technical features
Dynamically, weakly typed
JavaScript type system is dynamic. Both primitives and object values can be assigned to any variable because variables have no type associated with them. JavaScript type system is also weak because the language makes automatic assumptions on how to make operations on different type of variables allowing for example the sum between strings and numbers. Data types of the latest JavaScript version (whose standardized specifications go under the name of ECMAScript 6) are grouped into two categories: primitives and object.
Name | Type | Notes |
boolean | true/false | |
number | double-precision 64-bit floating point format (IEEE 754) | |
string | a sequence of Unicode UTF-16 code units | |
symbol | used for anonymous object properties (new in ECMAScript 6) | |
undefined | this is the type (which has a corresponding unique value with the same name) automatically associated to variables that have never been assigned a value | |
null | explaining why null is a type in JavaScript is beyond the scope of this introductory article on the language ;) |
Object-oriented
JavaScript is a prototype-based object-oriented language, meaning that every object in JavaScrit is an associative array whose initial properties are desumed by the prototypes chain associated with the object. These properties, which values can be primitives, other objects or functions, are completely customizable at runtime. Unless read-only, their values can be changed, new properties can be added, old ones can be removed. Contrary to class-based object-oriented languages, prototypes cannot be extended per se, but every prototype is linked to another prototype so that when object properties are accessed at runtime the interpreter look for them first in the prototype of the object itself, then, if not found, in the prototype of the prototype of the object and so on in a chain that ends with a null prototype. This means that neither multiple inheritance nor extension of primitive types are allowed in JavaScript. At the same time this prototypal inheritance model is very powerful and in fact building a class-based object-oriented model on top of it is very feasible which is why transpilation to JavaScript of other programming languages like Python, Java, TypeScript and the like is very possibile and frequently done.
Memory management
Memory management in JavaScript is automatic. A garbage collector provides to free at run-time the memory resources that become not needed by the program anymore. Details of the garbage collector in use are implementation dependent, for example Google V8 provides a generational, stop-the-world garbage collector.
JavaScript libraries/ecosystem
In itself, JavaScript, as defined by the ECMAScript standard, has very few built-in functions and data types. Most functionalities are provided by the execution environments the code runs in and the additional frameworks and libraries that programmers explicitly add at runtime. All the DOM manipulation functionalities that JavaScript applications uses in the browser, for example, are provided by the browser engine that's responsible to run JavaScript sources. This has many practical implications the most important of which is that nuances, differences and incompatibilities between implementations from different vendors have, and have done it especially hard in the past, negatively afflicted Javascript programming since its inception.
The second implication, which is a direct consequence of the first, is that during the years extensive libraries and frameworks have emerged that re-implement common funzioncionalities in a way that takes browser differences into account and smooths the incompatibilities between them, and often become the defacto standard at least for front-end software development, like the well known JQuery library.
In recent years, anyway, JavaScript have escaped the limited context of browser environments. Today JavaScript is also used to develop command line interface (CLI) applications, desktop (GUI) applications, mobile applications, backend infrastructures and any combination of all of them. This has resulted in the proliferation of libraries and frameworks for the language whose ecosystem has today reached gargantuan proportions, as evidenced by npm, the biggest package registry for JavaScript and the world's largest software registry, which has over 600,000 JavaScript packages and counts approximately 3 billion downloads per week. Today it is said that if for something there is a library yet ready, that's for sure in JavaScript.
Performance
JavaScript execution performance is strongly tied to the underlying JavaScript engine running the code. This is important to consider because no other language has so many different execution environments like JavaScript has, since the battle for the browser dominance is a longstanding and still ongoing battle between some of the biggest companies of the world. JavaScript benefitted this state of the facts especially from 2008 on when Google launched a race to create the most performant JavaScript execution engine of the world. As a consequence of this today all the modern execution engines have enjoyed stellar increases in execution speed when compared to the versions of the same engines even from just few years ago. Today these environments have way better garbage collectors, very performant just-in-time compilers and employs sophisticated optimization strategies at rutime to boost JavaScript execution as much as possibile.
Often server-side JavaScript performance, via the use of Node.js, is compared to those of Java. Here benchmarks and comparisons usually become confusing or even misleading. The problem in these kind of evaluations is that very often a number of key aspects of the matter are completely ignored like the fact that java have enjoyed many more years of research, optimizations and fine tunings on the server-side than JavaScript, and most of all JavaScript is not and has never been a language developed to handle the processing of concurrent requests and as such solutions like Node.js adopts mechanics (forking the process in many subprocesses and distributing the requests to them) that are inherently slower especially if some exchange of data between these processes is necessary. Java on the other side is a strongly concurrent language and employs hundreds of separate threads within the same process. On top of all this, anyway, the main question usually remain unquestioned: how many companies do really need the kind of sophisticated multithreading processing that Java offers? Usually if a service can be developed in such a way that its scalability can be attained by running the same software on more servers, unless we are talking of tens or hundreds or thousands of machines, the performance of the single server is way less important than a lot of other aspects, like for example the productivity a language offers to developers.
Notable softwares/platforms/products written in JavaScript
- Netflix leverages Node.js for its massive amount of A/B testing
- PayPal moved its backend development from Java to JavaScript and Node.js.
- LinkedIn moved its mobile app backend from Ruby on Rails to Node.js.
- Walmart re-engineered their mobile app backend adopting Node.js
- Groupon decided to rebuild their entire web layer backend on top of Node.js
- many many others, including NASA, Uber, Trello and so on use Node.js
Best books for learning JavaScript
For beginners
A Smarter Way to Learn JavaScript. The new tech-assisted approach that requires half the effort | |
Written especially for beginners. I wrote the book and exercises especially for people who are new to programming. Making no assumptions about what you already know, I walk you through JavaScript slowly, patiently. I explain every ... (continue on Amazon) |
For experienced programmers
Understanding ECMAScript 6: The Definitive Guide for JavaScript Developers | |
Whether you’re a web developer or a Node.js developer, you’ll find Understanding ECMAScript 6 indispensable on your journey from ECMAScript 5 to ECMAScript 6. Expert developer Nicholas C. Zakas provides a complete guide to the object types, syntax, and other exciting changes that... (continue on Amazon) |
Conclusion
JavaScript is the most evergreen of the programing languages, the most used, the most known (at least at superficial level) and the most hated and loved at the same time. While its adoption is increasing more and more and expanding in almost all the areas of the software development, its dynamic and weak type system feels tight for more sophisticated developments. Still the energies spent by some of the biggest companies of the world to create extremely performant execution engines for the language attracts for its potential to have a lightweight and still very powerful and easy to use platform to deploy and run stuff fast. Despite this it's hard to predict the future of JavaScript. In fact already today there are many dialects, variants, and completely different languages that are used as the real programming languages then transpiled to JavaScript for execution, so that programmers can access more high-level features like static type systems and so on. The question then is: what will be of JavaScript when and if technologies like the proposed WebAssembly standard will allow all the other languages to be directly compiled to browsers' native bytecode? To posterity the arduous answer.