5 Reasons why javascript is hated by developers.
Tags: javascript, webdev, frontenddev
Published: 2020-08-03 10:19:13

Javascript is a programming language build by `Brendon Eich` in April 1995. He was told to make a language to run in `Netscape's browser` and that too within `10 days.`
The hard part was producing a rich and powerful language while being prohibited from using the `object-oriented` syntax reserved for Java. A lot of developers hate this language. Below is a comparison of it from other languages.

![Comparision of programming languages](https://dev-to-uploads.s3.amazonaws.com/i/h30nd4c3stn64vkcfo26.png)

In this graph, you can easily see how fast javascript has grown in terms of job opportunities from 2019 - 2020. Now you may have a doubt why it is so popular even if there are so many people who hate this language. In this post, I have tried to give you some reasons why it is being hated.

###**Reason 1. Loosely typed language.**
Javascript is a loosely typed language, but what does it mean? It means that you don't have to declare the type of a variable while defining it.
* Case 1: Variables without defining any data types.

{% runkit %}
let a = 2;
console.log(typeof a); // logs out number
a="coding";
console.log(typeof a); // logs out string
{% endrunkit %} 


* Case 2: NaN is a number (quite confusing)

{% runkit %}
console.log(typeof NaN) // logs out number;
{% endrunkit %} 

* Case 3: You can mix different data types in an array.

{% runkit %}
array = ["banana", 2 , {name: "ankit" , lastname: "soni" } ];
// please click on the run button below to see the log.
console.log(array[0] +" "+ typeof array[0]); 
console.log(array[1] +" "+ typeof array[1]); 
console.log(array[2].name+" "+array[2].lastname+" "+ typeof array[2]); 
{% endrunkit %} 

###**Reason 2. Concept of "==" && "===".**

In very simple words "==" cares about equality of two variables without caring about the data types, whereas "===" cares about the equality as well as the data type of both the variables. Let's understand it better by the following example.

{% runkit %}
var a = 1;
var b = "1";
console.log(a == b); // prints true
console.log(a === b); // prints false
{% endrunkit %}
In third line of code, double equals does not care about the data types of the variables which are different and then prints true, whereas triple equals strictly care about the data types of the variables and hence prints false.

###**Reason 3. Functions can call themselves (IIFEs)**
IIFE stands for immediate invoked function experssion. Lets learn its logic.
{% runkit %}
(function(name) {
  console.log(name); //logs out "Welcome to the ankit's blog".
})("Welcome to the ankit's blog");
{% endrunkit %}

This function calls itself by adding parentheses at the end of the function definition.

###**Reason 4. Adding two variables of different data type**
Look at the following example and try to think about the output.
{% runkit %}
var a = "12";
var b = 3;
console.log(a + b);  // logs out 123
console.log(+a + b); // logs out 15
{% endrunkit %}

It logs out `"123"` and `15` in the console but how is it happening. Javascript says that when you add number and string then `number changes to a string`, whereas when you put a plus sign before a string then `string changes to a number` which is quite bizarre.

###**Reason 5. Javascript performs differently for different browsers.**
This generally happens due to the reason that every browser has its different ECMAScript engine which it uses to compile javascript code. Most famous ones are V8 by google chrome and spiderMonkey by mozilla firefox. Javascript is different from languages like c, c++ and java. Java codes are compiled the same on all the devices which are using JVM in their machines, but that does not happen with javascript. Hence a developer has to look at how their website is performing in different browsers.

###**Conclusion**
I showed you a lot of negatives about this language but don't dare to judge this language to be crappy. It has a huge internet community, as well as a lot of frameworks and libraries, are running on it. Below is the list of some of them.

* Front-end: [Reactjs](https://reactjs.org/), [Angular](https://angularjs.org/), [Vuejs](https://vuejs.org/), [emberjs](https://emberjs.com/) etc.
* Back-end: [Nodejs](nodejs.org/en/)
* mobile-development:[React native](https://reactnative.dev/) and [ionic](https://ionicframework.com/)
* game-development: [Phaser](https://phaser.io/), [babylonjs](https://www.babylonjs.com/) and [playcavasjs](https://playcanvas.com/)
* Desktop application: [electron](https://www.electronjs.org/)

If you are still reading it. Consider reading my blog on `promises` by clicking on the following link.
{% link https://dev.to/ankysony/how-did-promise-evolve-in-javascript-2fcp %}Thank you!