Why is JavaScript called a lightweight programming language?

JavaScript is considered a lightweight programming language because it has low CPU usage, is incredibly easy to implement, and has a minimalistic syntax. Some people will also use lightweight in a derogatory way to try and indicate some of JavaScript’s shortcomings.

Remember that JS is the most used programming language in the world. While it may be a lightweight language by definition, you can achieve incredible things with the versatile language. 

Let’s take what defines a lightweight programming language and then understand why JavaScript is considered to be lightweight. 

What is a lightweight programming language?

Weight training

A lightweight programming language does not use much memory, is easy to implement and port over, and has simple syntax and features. Lightweight does not refer to the language’s capability or usefulness, even though it is thrown around as a way to insult certain languages used in development. 

Generally, they have simple syntax so they are easier to learn. Plus they are generally easy to implement so have a few different flavors. There are numerous other lightweight languages which include:

  • Lisp and its many implementations include newLISP, PicOLisp, and uLisp
  • TCL
    Wren
  • Io
  • BASIC
  • Forth

JavaScript is considered easier to learn than other, more syntax-heavy, languages like C++. Also, JavaScript is an implementation of ECMAScript and follows the rules, guidelines, and details to be ECMA compliant. In terms of other flavors, or implementations there is: 

  • Duktape.
  • Espruino.
  • JerryScript.
  • Jsish.

These are just other lightweight implementations of ECMAScript, which is the standard to which JavaScript aligns. But the prevalence of so many variations of ECMAScript proves it is lightweight.

Why is JavaScript a lightweight programming language?

JavaScript is a lightweight programming language because it has low memory usage, simple syntax & and features, and is easy to implement. Its popularity has exploded as developers can easily start learning and because it’s become even more powerful yet remains so lightweight. 

If you read forums online you will see the word lightweight also used in a derogatory fashion between programmers of different languages. However, a lightweight programming language is well defined and doesn’t rest on the opinion of internet trolls.

JavaScript is not the only lightweight implementation of the ECMA standard, others include:

  • JerryScript.
  • MuJS.
  • QuickJS.
  • JScript

Let’s explore the different elements that comprise a lightweight language and see how JavaSript lines up.

Memory footprint 

A lightweight language does not consume a lot of your CPU’s resources. It doesn’t put excess strain on your CPU or RAM. JavaScript runs predominantly in the browser even though it has complex paradigms and logic which means it uses fewer resources than other languages. 

One study of NodeJS which is a variation of JavaScript used on the backend found some interesting results. Not only did Node finish some computations faster but it uses far fewer resources than its Dart and Java counterparts. C++ finished faster and used less memory overall but had far higher CPU usage.

Easy of use and learning 

JavaScript is a scripting language at heart, it means it is far easier to learn and use than its heavier programming companions. JavaScript is compiled at runtime and interpreted by your browser so the setup is a lot easier than Java which has to be compiled first. If you are tossing up whether to learn Java or JavaScript first, in terms of ease JS definitely wins.

Lightweight languages like JavaScript also require less tooling to get started. They are easier to build and deploy, and make for a great first language because you get instant feedback via the browser.  You also don’t have to worry about static typings when you first start so the learning curve is smaller – although TypeScript has now paved the way for this. 

If you are looking to learn some syntax and tackle a few JS-focused programming problems HackerRank is a good place to start once you have nailed the basics.

Simple Syntax

Lightweight programming languages like JavaScript and Python have simpler syntax than C or C++. It makes it far easier for beginners to pick up and learn the intricacies of the languages. 

Take the examples below of logging out “Hello World” in JavaScript and C++. As you can see C++ takes far more lines to set up than JS.

JavaScript is shorter and more readable which makes it lightweight, while C++ is longer and more difficult to read making it heavyweight. Either way, they are both considerably easier than learning high-level math concepts!

The lack of strict typing in vanilla JavaScript means that there is no need to specify return types, or the structure of data you pass to functions. Although it can be a good and bad thing, it decreases the number of lines of code you need to make a program work. 

Features

Lightweight languages come with fewer built-in features than their heavyweight counterparts. It makes them great for getting set up and working with the language. However, it also means they are less powerful.

The ecosystem of a programming language tells us a lot. Heavyweight languages have a lot of libraries and frameworks built-in, so they come with more but are slower because of this. JavaScript on the other hand is super lightweight but can often require a lot of external libraries or frameworks to make working it is much easier. You don’t need these external add-ons but they help a lot.

JavaScript avoids becoming bloated by deferring these other features of its ecosystem. It keeps core JS lightning fast. However, we could argue that it becomes less lightweight as more ‘essential’ libraries and frameworks are released.

Resources