+ 2
Equal
What is the difference between == and ===?
3 ответов
+ 17
In javascript:
== checks for data equality (1 == "1" // true)
=== checks both data and type (1 == "1" //false, number != string)
+ 7
As my friend @ValentinHacker said above, you can check this lesson in SL lesson:
https://www.sololearn.com/learn/JavaScript/1132/
+ 3
We often get confuse, while working with these kind of operators. I would like to tell the difference between "=","==","===".
1.) Let's start with "="(equals to), this is known as the assignment operator, i.e. it assigns the value lies right to it, to the variable lies left to it.
e.g. a = 5.
This means 5 is assigned to a.
2.) Now, let's discuss the "==" operator. This is known as the comparison operator, as it checks if the two values used with it are equal or not. It gives the output in true or false.
This is not much strict. e.g.
"5" == "5" gives true.
7==6 will give false.
True == 1 will give true as the Boolean equivalent of True is actually 1, so it is equal.
3) The last one "===" operator. This is also known as the comparison operator. However, this one is bit strict.
Rather than checking only the values it checks the type also and if the type comes out to be different it will result into False.
e.g. let's take the last example of previous point.
i.e. True === 1 will return False here because even both are equivalent to each other but the type of both the operands are different. One is of Boolean type and other one is an integer.
Well, these are the basic difference among three of them. I hope, I was able to clear the doubts.😊😊