Where we Use === in JavaScript – What is difference between == operator and === operator in JavaScript

Here is another interested JavaScript tutorial for programmers and beginners, I describe where you can use === comparison operator and == comparison operator. And what is difference between these operators.

The comparison === operator compare the two values, if it is equal or not as well its data type and it return True if vale is equal and same data type while == operator return True whether the data type of operand are same or not.

Here are some more examples:

1. For operands data type is number then :

var x = 1;
var y = 1;

x === y returns true if x and y have the same value and are of the same data type.
x ==y returns also true.

2. If both operands data type is string.

var x = “abc”;
var y = “abc”;

x === y returns true if x and y are both strings and contain the exact same number of characters.
x == y returns also true.

3. For operands data type is different but have same value (==):

var x = 1;
var y = “1”;

x === y returns False if x and y have same value but different data type.
x == y  returns True if x and y have same value but different data type. Data type is not matter in == comparison operator.

Now you understand the use of === operator and == operator in JavaScript. Once again i tell you that wherever you want to compare value along with it data type use === comparison operator, whereas use == operator if you would like to check only value of variables.

About Moazzam Qureshi

I am SEO expert and web developer since 2011. My hobby is to write & provides quality content about blogging, SEO , Social Media , Earn Online and Affiliate Marketing.