Can JavaScript Be Used for Data Science?

JavaScript is the backbone of the Internet. Created in the 90s as a way to manipulate content in web browsers, it has grown both in popularity and functionality. It has become one of the most popular programming languages in the world.
With its rising popularity, many wonder whether it is suitable for data scientists and data analysis in general. The answer is not so simple. Let's look at the pros and cons of JavaScript as a Data Science language.

The Argument Against JavaScript

No sane data scientist would recommend beginners start with JavaScript. Python, R, Scala, and Julia are often mentioned as programming languages for data science. But why is that?
David Beazley, author of "JavaScript for Data Science," mentions in the early pages that he originally planned to title his work "JavaScript vs. Data Science" in recognition of JavaScript's reputation.
JavaScript is known for its many quirks, some of which are related to working with numbers. An example is the IEEE 754 floating-point NaN (not a number), which was introduced as a representation of a value that cannot be represented within the constraints of the numeric type.
Simply put, divide by zero and JavaScript returns NaN. Not the most informative or helpful response. Worse, the language still recognizes NaN as a number, so if you only check the type, you won't catch that pesky villain.


To be honest, this is a minor inconvenience, but it points to a much broader issue: JavaScript is dynamically typed and has a rather loose way of determining what is a number or a string. Again, nothing that cannot be avoided, but it definitely requires some coding precautions.
Working with large numbers is also problematic. JavaScript is not only imprecise with large numbers but also lacks support for multithreading and parallel processing, so big data is out of the question. Neither JavaScript nor Node.js is suitable for computationally intensive, CPU-bound tasks.
Most of these issues can be resolved, but the final nail in the coffin is the opportunity cost. Why would a data scientist spend a huge amount of time learning JavaScript when there are already many languages that do it better and with less effort?
Every hour spent on JavaScript is one hour less spent on other languages... but that may not be such a bad thing.

The Case for JavaScript

The main argument in Beazley's book is that modern JavaScript solves many of these issues, and the JavaScript community's interest in data science has grown exponentially over the past few years. This has led to tools and resources that make JavaScript a competitive choice.
Perhaps the first argument for JavaScript is its ease of use and readability. For example, if you are reading this article on a computer, simply press F12 and you immediately get a JavaScript console ready to use.
JavaScript is very easy to learn, and thanks to its popularity, there are literally thousands of resources to help you master its nuances. A quick look at StackOverflow statistics shows that the amount of information on JavaScript is simply overwhelming.


Another argument for JavaScript is that more and more companies are using web technologies with a Node-based stack to build their products. If a data scientist is going to work closely with product developers, sharing a common language is undoubtedly an advantage.
Moreover, the fact that everyone works with the same technology means integration with other products and services becomes easier, requiring less overhead and preparation. Just as it's easier to communicate when everyone speaks the same language.
TypeScript, a superset of JavaScript developed by Microsoft, addresses one of the main criticisms of JavaScript—its weak typing. In fact, with TypeScript, the language has become stricter than Python, which is beloved by data scientists. Statically typed languages tend to encourage better practices and fewer code errors, which is why there is a boom in companies and services using TypeScript.
Speaking of Microsoft: Napa.js is a fantastic alternative to Node.js if multithreading is a concern. It is still in early stages and not the most optimal solution, but it shows how much interest there is in advancing JavaScript as a universal programming language, including for data science. But that's not all...

New Tools for Data Science

One of the most common arguments against JS is the lack of data manipulation libraries characteristic of more robust solutions like R and Python. We absolutely agree with this argument. Even the most ardent JavaScript advocate would have to admit that any aspiring data scientist needs another tool in their toolkit.
The data science landscape for JavaScript is growing exponentially. Five years ago, no one would have thought that TensorFlow would have a functional JavaScript library, and here we are.
Moreover, the ecosystem for data science in JavaScript is growing. Take D3.js, for example, a popular data visualization library that provides a fantastic set of tools for creating dashboards, reports, and data stories through the browser.

Another great example is TensorFlow.js. For those who don't know, TensorFlow is one of the most popular machine learning libraries. With its JS variant, you can run machine learning algorithms directly in the browser and/or on a Node.js server.
But why would you need this? Yes, the browser environment is not the most optimized workspace. But on the other hand, it is very convenient for quick prototypes, small projects, and applications that don't require a lot of memory. Why create a virtual environment when you can just use a simple browser?

The fact that we are getting such tools for the language that powers the Internet and web applications in general opens up new possibilities. Thanks to browser-based data science, we can experiment with new ways of processing and presenting data in a friendly environment.
Imagine having a web application that serves as a presentation for your data story, all coded as a frontend solution using JavaScript, HTML, and CSS. Anyone with a smart device and an internet connection can access the results within seconds.
This surge in JavaScript usage in Data Science indicates that the field is expanding. Data scientists are no longer expected to sit in a dusty corner analyzing data. They become storytellers who must find ways to present their findings and create a data-driven environment.

Another Tool in the Arsenal

Perhaps we are not yet ready for a world where knowing JavaScript is enough, but as a supplementary skill, it is excellent for data scientists. Importantly, it won't revolutionize the field, but it will increase its scale and reach. Ultimately, this is a positive outcome.