Double Equals (==) vs Triple Equals (===) in Modern JavaScript

In this post, we will look at two of the comparison operators in JavaScript, they are Double Equals and Triple Equals. We will look at the difference between them with an example.

Double Equals (==)

Double Equals compares only the value irrespective of the data type. Let us look at the example for Double Equals.

var a = '34';
var b = 34;
console.log(a==b); //true

In the above example, I have initialized a and b with value 34 (a is string and b is an integer) and compared them using Double Equals. It gives me the result as true. So, irrespective of the data type, only the value is compared which is the same in our case.

Triple Equals (===)

Triple Equals compares value and data types both. It has strict equality. Let us look at the example for Triple Equals.

var a = '34';
var b = 34;
console.log(a===b); //false

In the above example, I have initialized a and b with value 34 (a is string and b is an integer) and compared them using Triple Equals. It gives me the result as false. So, here strict equality is present that compares both value and data type.

Thank you All!!! Hope you find this useful.


Up ↑

%d bloggers like this: