Using JavaScript for everything — The pros and cons

Bello Mubarak
6 min readMay 24, 2019

--

Perhaps you are writing a compiler in JavaScript already? Stop it and read!

The browser-only language has evolved into a universal-purpose language over the years with the advent of several tools that makes it usable in
environments outside of the browser.

With the syntactic sugar additions of ES6 and the advent of tools like NodeJs, Webpack, etc, you can now make full-fledged desktop applications that have full access to desktop native APIs and hardware resources, native and hybrid mobile applications for Android and iOS devices, simple and complex command-line tools, server technologies, machine learning tools and libraries, system scripts, blockchain, video games, etc.

Javascript everything? Maybe not!

In this article, we’ll be looking at some tools and libraries that make this possible, and their pros and cons (if any!).

The Big Bang Theory for JavaScript

Javascript started out fully in the browsers to power the DOM formation and manipulation. With this, developers can add interactivity to their
HTML layout and conditionally style web pages.

With the advent of browser workers and better storage options, web applications are powered into what is called Progressive Web Applications and this is one of the many attempts to making web apps feel native. A web app can be added to the home screen of devices, and when launched will open
up as if it’s running as a standalone native app and not in a browser.

When runtime environments like NodeJS came, Javascript developers now have a runtime to use in environments outside of a browser. Now, this is
the bomb — we are no longer restricted to coding for the browser, and we can now do virtually everything other scripting languages can do. Majorly
though, you’ll see people using NodeJs for powering backend scripts.

Runtime environments like NodeJs made it possible to organize our code into reusable modules (at least, before ES6 imports were added), to write
software that needs internet communication, to work with files and file systems, to deal with more complex databases aside the ones available in
browsers, to access operating system level APIs, to create child processes to leverage parallel processing on multi-core CPU based systems, etc.

With ES6 additions, Javascript now has some syntactic sugar that makes it super cool to develop in. Importing and exporting in modules now became
a language specification, the class keyword can now be used for making classes (although this is just syntactic sugar to the function constructors
that has since been existing), etc.

Your face right now, yeah? 😉

Now, let’s explore some tools and libraries that made all these possible, and their strengths and limitations.

Single and Multiple Page Apps (in short, web applications!)

No competition, Javascript is the programming language of the web. With HTML5, CSS3 and web frameworks like ReactJs, AngularJs, VueJs, Meteor.js, Ember.js, etc., Javascript developers are enjoying a language monopoly!

That’s Javascript talking to web developers! 😔

Are there any limitations or reasons why you shouldn’t use Javascript for SPAs and MPAs? Maybe, maybe not. I guess nobody cares because we are forced to use it!

Mobile Apps Development (iOS, Android)

The use of Javascript for mobile application development is on the rise with the advent of libraries such as ReactNative, Ember.js, PhoneGap, Ionic, NativeScript to mention but a few. While some of these frameworks give you a completely native application, some just give hybrid apps.

One of the upsides of taking this approach to mobile apps development is that the Javascript/web developer ecosystem is incredibly large, and the learning curve is always steep (easy to learn) as compared to other languages such as Java, Kotlin, Swift or Objective-C. What this means for business owners or employers is that they’ll spend less acquiring competent developers in fields of Web development and Mobile application development.

Another advantage is that these frameworks give cross-platform apps, which means the same logic written in the same codebase can be used to make Android and iOS installables.

However, JavaScript is up against many mobile native language competitors where it’s clearly disadvantaged. It has no hope of displacing Java or Kotlin(for Android) and Objective-C or Swift (for iOS). This is not a big problem actually — several wonderful apps are still being made with Javascript!

Desktop Apps Development (Windows, Linux, MacOS)

ElectronJs and AppJS are popular amongst the numerous Javascript libraries you can use for building desktop applications, mostly cross-platform! Powered by NodeJS, these libraries majorly work by coupling a web browser engine into each app to render webpages that connect with the OS through JavaScript API. Good time to learn Javascript, yeah?

Though, if you are utterly concerned about the operational speed and memory consumption of your apps, tools like ElectronJs and co are probably not your best bet.

Yeah, I know. Sorry!

Electron applications, particularly, are greatly bloated in size and are relatively sluggish — an Electron app comes with its own version of Chromium which is made of over 20 million lines of code nearly the size of a whole Operating System! Now imagine running two or more desktop apps built with Electron at the same time, you have two or more Chromium processes sucking up your memory!

Again, very powerful desktop apps developed with Javascript are widely used daily, take VSCode, Atom editor, Slack Desktop and WhatsApp Desktop as an example!

Data Science and Machine Learning

It’s no news that most data scientists work with some combination of Python, R, and SQL — these are actually the languages you should consider mastering first if you are new to the field!

Using JavaScript, however, makes data science and machine learning easily accessible to web and frontend developers, a group that historically has been left out of the DS/ML discussion. Though DS/ML with Javascript isn’t so popular at the moment, as demand for these applications rises, and as hardware becomes faster and cheaper, it’s only natural for DS/ML to become more prevalent in the JavaScript world.

Some libraries and frameworks you should check out for DS/ML in Javascript include ml.js, TensorFlow.js (owned and supported by Google), Brain.js for neural networks, KerasJs, etc. With these, you can do stuff like gesture recognition, object recognition, music composition, data processing, multi-label classification, feature engineering, online learning, and real-time classification, you name it!

Enough pros mentioned, some cons to using Javascript for DS/ML includes:

  • It is not advisable to use Node.js for CPU intensive applications and this is a big blow as it is often helpful to process large data sets or run simulations in parallel.
  • Currently, JavaScript just doesn’t have the range of data science packages and inbuilt functionality compared to languages such as Python and R. This might be less of an issue though if you don’t mind developing these functionalities yourself!
  • Also, the ecosystem for machine learning development with Javascript is pretty immature compared to other languages such as Python or R.

However, you can trust the Javascript ecosystem to mitigate these disadvantages! For one, there’s currently Napa.js, a multi-threaded JavaScript runtime being developed by Microsoft to complement Node.js in CPU-bound tasks (with the capability of executing JavaScript in multiple V8 isolates and communicating between them… Check out the project website for more details). Plus, libraries such as Tensorflow.js keeps getting updated with new tools!

Embedded Systems and Internet of Things (IoT)

You should check out iot.js and JerryScript! iot.js (which is intended to run in resource-constrained devices such as only a few kilobytes of RAM available device) runs on JerryScript, a lightweight JavaScript engine intended to run on very constrained devices such as microcontrollers. So they fit perfectly!

Generally, you’d want to go for compiled languages (Javascript is interpreted, sorry! 😞) because they run faster and more efficiently. With increasing computing power nowadays, however, this isn’t really a problem — just that sometimes embedded systems need to be low power which requires the efficiency of compiled languages.

Another disadvantage is that JavaScript stores all variables in floating-point format, and this storage format can be very unreliable because of the errors in floating point arithmetic. Plus, it will be slower in many embedded devices that do not have floating-point-units — using fixed-point variables is usually more reliable and faster.

Don’t forget to check out Espruino though! It’s a JavaScript microcontroller you can program and debug wirelessly. So yeah, you can develop those fancy hobby electronics projects with Javascript too!

Video Games, Blockchain, Scripting and co

Really, NodeJs has made virtually anything possible. However, these fields sometimes require CPU-intensive tasks, and that’s considered a no-go area for NodeJs. You can still try out that Microsoft’s Napa.js though.

As you’ve seen for yourself, Javascript is no longer all about document.getElementById or $(document).ready. Having been sidelined in other areas aside web, we have to commend the Javascript community’s creativity for the traction it’s gaining recently!

With the numerous options available now, you just have to weigh your options before deciding whether it is the right choice for your project!

That’s it! Got any questions, opinions or comments? Feel free to drop them below. Thanks for your time.

--

--

Bello Mubarak

Python 🐍 | Js Front-end web dev 😇💪💻 Computer engineering student at OAU **Bio link: https://about.me/mubarak-bello