difference between “==” and “===” in JavaScript

This is very common question asked in JavaScript related interviews because generally everyone is used to of “==” but we should know the difference between “==” and “===” in JavaScript. 

Since JavaScript support both strict equality and type-converting equality, it’s important to know which operator is used for which operation.

The double equal “==” is an auto type conversion and used to compare by the value only whether it is a variable or a constant. 

The three equal “===” is a not auto-type conversion and used to compare by it’s type and value both. If type is not the same but value is same then also it returns false.

The real examples are as follows:

but if we cast or convert the type of  “1”  then we can compare and it will return type as below

That’s all about difference between “==” and “===” in JavaScript, you should always use strict equality operator i.e. === and avoid using == operator even if you need type coercion, instead convert the type by yourself to make it more readable.

Like this Post? Share