Why JavaScript is Popular Despite Being a Crappy Illogical Language

JavaScript is one of the most hated popular programming languages. When I tried to search with “JavaScript hated”, Google returned 17.000.000 results while with “Python hated”, I got only 1.880.000 results. Quite the big difference!

Image for post
Image for post
Image for post
Image for post

Still, JavaScript is one of the most widely used programming languages. As reported recently by TIOBE, JavaScript has 3.3% of market share and the language was ranked at 6th position in the list of top 20 programming languages as of January 2019.

Image for post
Image for post

These two points contradict so much. Why do people use a language, which they hate so much? This post will give you some reasons.

Why JavaScript is So Hated

Like any other programming languages, JavaScript has its drawbacks and bad sides. After all, you should not expect much from a language supposedly has been designed within ten days. However, some are just too much. Below are some of the most common complaints.

IEEE 754 — Nightmare

JavaScript designers decided to use IEEE 754 Double Precision and you have only one number type ‘Number’. The precision sometimes is very funny.

9999999999999999 == 10000000000000000 → true
0.1 + 0.2 === 0.3 → false
x = 1.0000000000000001
x === 1 → true

Funny? This example is perfectly correct while following IEEE 754 Double Precision Standard, but it leads to errors if programmers are not aware of this fact.

Another funny case is when Not a Number is also considered as Number.

typeof NaN == 'number' → true
NaN != NaN → true

Browser Dependency

Some features in JavaScript are browser dependent. Many functions and properties are executed differently across browsers. Hence, don’t be surprised if what you see on Chrome is different from Internet Explorer.

Weak-Typing and Aggressive Coercion

In addition, JavaScript practices an extremely aggressive type coercion doctrine. This loosely-typing language, thus, tries to convert different types to one another. It results in some odd effects. For example, a ‘+’ could mean adding numbers together or adding a number onto a text, or text onto a number.

Let’s see some weird examples:

var a = "1"
var b = 2
var c = a + b → c = "12"
var d = +a + b → d = 3, note the unary plus sign (+a)
[] + [] → "" // adding two arrays and you have a String!
[] + {} → [object object]
{} + [] → 0 // I don't even know how to explain
{} + {} → NaN // ???
// Funny arrays
19 == [19] → true
19 == [1,9] → false
"1,9" == [1,9] → true

The semantics are quite irrational and crappy illogical!

Excessive Boiler-Plate Code

JavaScript is quite a verbose programming language in nature. Thus, the language and its frameworks like React have a lot of boiler-plate code or repetitive code that you have to put in several necessary places in order to avoid any unexpected errors. This takes time and efforts.

Annoying Global Variables

Like most other programming languages, JavaScript also provides support for global variables. Well, it’s very important to have global variables. However, the way JavaScript handles global variables is quite annoying. The global variables have scope or accessibility in the whole program, so you never know whether they have been changed somewhere in the program by you or possibly by any third-party libraries which might be using same variable name as the global variable you have declared before.

Also, there is a concept of Implied Globals. If you misspell your variable then JavaScript will not show an error, instead, it will declare that typo as a new global variable (unless you use 'use strict' in your code). It results in a new global variable that you never intended to.

function foo() {
var bam = 'This is a not a global variable';
//
// [... Some code...]
//
ban = 'Typo and now you have a global variable';
}

Still not annoying enough? Then let’s see

function myLoop() {
var sum = 0;
for(i = 0; i < 10; i++) {
sum += i;
}
return sum;
}

In the example above, i was declared without var or let or const and hence, it’s global. Good luck using i anywhere else in your program.

Why JavaScript is still So Popular

JavaScript has many flaws. Many people consider it a crappy language. However, no one can deny the fact that it is one of the most popular programming languages. In this part, I will explain why.

No Better Choice Than JavaScript When it comes to Web

Still, even after more than 20 years, there is no better choice than JavaScript for web development. Well, PHP is also hated by so many developers.

Together with HTML and CSS, JavaScript forms the Holy Trinity of the web. In addition, in order to use jQuery, one of the most popular libraries for front-end development, it is required to have a basic understanding of JavaScript. Same stories for many useful frameworks which I will mention later.

In short, JavaScript is very popular with Web-development. We have no (better) option than using JavaScript in the web.

JavaScript is Easy-To-Pickup & Easy-To-Use

JavaScript is easy-to-pickup language because JavaScript code can be written by any simple code editor and executed directly into web browsers. Thus, there is no need to download or install any heavy development platforms or software to write and run JavaScript code. Anyone can start learning and using JavaScript straightaway.

Furthermore, because the JavaScript code can be run on the client-side, any code functions can be executed immediately on the user’s computer processor/memory space instead of having to contact the server and wait for an answer. The demand on the web server is hence reduced. This feature also makes the learning process or development much faster.

High Flexibility for Web Development

With JavaScript, it is possible to develop a complete website thanks to its rich set of frameworks for both front-end and back-end development.

JavaScript consists of powerful libraries and frameworks that are used at different levels. For example, Node.JS supports server-side scripting and React, Vue for the front-end development.

JavaScript is Everywhere

Image for post
Image for post

Although JavaScript is famous for Web development, the language is not limited only to this field. Its usage is very wide:

  • Web Application: React Native and Ionic are the good names for such use case. There are several other good frameworks supporting the development of the hybrid application;
  • Data Visualization: There are tons of options with JavaScript when it comes to data visualization. For example, D3.js, Chart.js, Raphael.js or Leaflet. These libraries and frameworks are lightweight and very easy to use;
  • Robotics and Internet of Things: Johnny-Five supports robotics and IoT programming very nice. It is compatible with hardware devices like Arduino, Intel Edison Tessel 2, and Raspberry Pi etc;
  • Game Development: JavaScript also has solid space in game development. Using Phaser.JS framework, we can build large web-based or online game applications.

Large Community

JavaScript has huge support from tech giants like Facebook, Microsoft, Google, and Alibaba. This language has a very promising future. Its community is big so it is very easy to ask for support.

Conclusion

There are only two kinds of languages: the ones people complain about and the ones nobody uses — Bjarne Stroustrup

In short, the reasons why this crappy language is widely used are:

  • There is no better alternative than JavaScript especially in web development, as JavaScript is one of the three core components of world wide web alongside HTML and CSS;
  • JavaScript is very easy to learn and to use;
  • JavaScript is very highly flexible. It can be used for many different tasks thanks to many useful frameworks and libraries;
  • Its community is large and thus, it is easy to get support.

JavaScript is widely used. Thus, it is very understandable for its to get a lot of complaints.

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store