This Is The Year To Use JavaScript For Machine Learning, Here’s Why

With 2020 fading over the horizon, we can finally reflect on ‘what was’ versus ‘what could have been.’ It was undoubtedly the year of many upended plans, with countless surprises and course-changes along the way.

But there’s one resounding takeaway from the last twelve months. And it’s unlikely to change this year: JavaScript has grown in profile and popularity, with machine learning one domain where the programming language has found an unlikely home.

Let’s look at how Javascript prospered in 2020 — and share some predictions for what 2021 might hold.

From Simple Scripts to Machine Learning

JavaScript hails from humble beginnings. It entered the scene in 1995 as part of Netscape’s Navigator web browser. Its purpose? To make the web more dynamic. The programming language’s creators designed it to be easy to implement, powerful, and functional.

It was precisely what an emerging internet needed. And the creator’s succeeded in their cause. But it wasn’t long before the next milestone arrived with a standardization process that started in November 1996 (ECMA International named the standard ECMA-262). 

By this time, JavaScript had established itself as a notable player in web development. In a Netscape press release, the company confirmed almost 300,000 JavaScript-enabled pages across the nascent worldwide web. 

“JavaScript and Java are cornerstone technologies of the Netscape ONE platform for developing Internet and Intranet applications. 

In the short time since their introduction last year, the new languages have seen rapid developer acceptance with more than 175,000 Java applets and more than 300,000 JavaScript-enabled pages on the Internet today according to www.hotbot.com.”

Source: www.web.archive.org

Standardization played a pivotal role in JavaScript’s growing profile since it enabled developers to use it, alongside giving them a voice in the evolution of the language itself.

Moreover, standardized usage ensured consistency in implementation, stopping developers from deviating too far from specifications, which could have caused fragmentation, undermining JavaScript’s scalability. 

That said, some feared Microsoft might intentionally pursue such a strategy to gain a competitive advantage in the early days. But thankfully, those predictions never came to pass.

Despite the language’s growing profile, the ECMA committee couldn’t use ‘JavaScript’ as the name for their standard because of trademark issues. All the while, the committee couldn’t find a name that developers and implementers would accept either, so they settled on ‘ECMAScript.’

But JavaScript is only the commercial name for it. And with every new release — spanning ES2 in 1998, ES3 in 1999, ES5 in 2009, and ES6 in 2015 — the language has gained more and more traction.

ES5 was the release that introduced many features that dramatically increased ease-of-use, angling JavaScript towards becoming a general-purpose language. And the release of Node.js confirmed just that. 

Following the ES6 release, no doubts remained about the ambition behind the language as the world gained access to the following features:

  • Default Parameters
  • Template Literals
  • Multi-line Strings
  • Destructuring Assignment
  • Enhanced Object Literals
  • Arrow Functions
  • Promises
  • Block-Scoped Constructs Let and Const
  • Classes
  • Modules

At this point, it was clear JavaScript wanted to dominate the market, alongside appealing to developer groups using other languages. With its increasing functionality, its popularity only grew. 

Then Node.js arrived in 2009, allowing JavaScript to finally escape the browser and find use in servers before it eventually found its place in machine learning — largely thanks to the increasing computational power of end-user devices.

JavaScript for Machine Learning

For many years, JavaScript has been popular both among developers and in business. 

Check resources like Tiobe, Stack Overflow, Github, and HackerRank, and you’ll find JavaScript in the leading position for the most-used, popular or in-demand language. According to HackerRank, it’s also the most sought-after programming language by employers.

Source: HackerRank

Whatever the source, you’ll find JavaScript mentioned in the lead for machine learning, in the company of mainstream languages like Python, Java, or Go. 

In reality, Python is the unquestionable leader in ready-to-use dependencies for almost any case, including machine learning. But JavaScript isn’t far behind, thanks to its maturing range of packages coupled with comprehensive developer and business support. 

Here are the five most popular JavaScript libraries around today:

Despite its growing use, you might still ask yourself, “Is JavaScript for machine learning really a thing?” In short, yes: the reason being that it is already a prevalent language and one with a relatively low entry threshold. 

Plus, there’s an abundance of specialist developers who already use it. Not to mention the possible cost-reductions in using an AI infrastructure, given that execution happens in the user’s browser. 

Ease-of-deployment is another selling point, as is the ability to gather and combine data from many sources. So yes, absolutely, JavaScript for machine learning really is ‘a thing’ — and it’s little wonder the language is growing more popular by the day.

Top Machine Learning Languages on GitHub

Source: GitHub

Development of Popular JavaScript Libraries

Let’s take a moment to consider how the most popular frameworks grew in 2020:

Framework

[Github stars][start date]

[Github stars][start date]
Tensorflow.js

12.4k January 2020

14.4k December 2020

Brain.js

10.5k December 2020 

11.6k December 2020

ML5.js

2.4k March 2019

4.4k December 2020

ConvNetJS

9.9k December 2019

10.1k December 2020

Synaptic

6.7k January 2020

6.7k December 2020

In many ways, each library’s growth is down to the growth of the AI market itself.

According to IDC, the global AI market was worth $156.5 billion in 2020: an increase of 12.3% from 2019. And with JavaScript being the most popular programming language worldwide — with both browser and server environments at its fingertips — it’s unlikely to fall by the wayside. 

Case in point: Tensorflow was popular among Python users, and it rocketed to fame the second it was released for JavaScript. Many libraries are following suit. But there’s one exception. 

Synaptic is less popular, but that’s mainly down to its age. 

Development started in 2014. Still, over the years, it has proved a reliable library for building neural networks. And while development isn’t overly active, Synaptic often features as a recommended library.

Where JavaScript Underperforms Other Languages

In my previous article, I pinpointed three shortcomings when using JavaScript for machine learning — they were:

  1. Online-only: The model won’t work offline (unless you configure the web app to work offline, which is rare).
  2. Reliability: Performance relies on the end user’s device.
  3. Public: Your code and model are publicly visible.

Interestingly, my observations on this topic overlapped with the findings presented at this year’s W3C Machine Learning Workshop. And there’s still a need to standardize how we use ML models on the front-end. 

Doing so would reduce computational issues (for example, a lack of float16 reduces hardware acceleration) and privacy issues (for example, the privacy of models and processes around user data collection).

W3C is considering standardizing the Neural Network Web API — which would, in turn, make machine learning accessible to a broader user base and resolve the three issues.

Where JavaScript Outperforms The Competition

Despite its shortcomings and ongoing lack of standardization, JavaScript still has several advantages, including:

  • Deployment: It’s easy, you can even use a static website with Javascript added.
  • Ubiquitous: You can gather and connect data from multiple sources (like social media).
  • Reach: You can access end-users via a pop-up, no need to install anything else. 
  • Mobile: You can port to mobile using React Native.
  • Availability: JavaScript works offline with the right configuration.
  • Lightweight: JavaScript is lightweight.

What Can You Expect for JavaScript in 2021?

JavaScript has reached a tipping point. 

We expect its usage to explode in 2021, including more comprehensive integrations of JavaScript-based solutions, with not only the internet benefiting from improvements in the programming language.

But mobile platforms (through React Native), server apps (through Node), and desktop (through ElectronJS) as well. On the global stage, Statista predicts JavaScript penetration will hit 53.7% as it reaches new frontiers.

And one application to note is how SpaceX’s very own Dragon Capsule uses Chromium and JavaScript to drive the UI of the vehicle’s controls. We don’t expect SpaceX to be JavaScript’s final frontier. Quite the opposite.

It’s just another round of rocket fuel for this hugely popular programming language.

Krzysztof Miśtal

JavaScript Tech Lead focused on everything JS. He is also fascinated with cameras.

Read more on our blog