2

in dreamweaver cc 2015, when i am using the comparison operators in jquery/javascript programming like:

 if(x == "")

DW shows an error that Expected === and instead saw ==. My question is that what is the difference between === and == ?. As i know in other languages like C# etc the === operator means that the comparison will check the Data Type of the value as well as the value. In javascript or jquery is there any problem if i use the == instead of === ? or still the result will be the same in jquery / javascript?

Abdul Rahman
  • 1,669
  • 4
  • 24
  • 39
  • 3
    Possible duplicate of [Which equals operator (== vs ===) should be used in JavaScript comparisons?](http://stackoverflow.com/questions/359494/which-equals-operator-vs-should-be-used-in-javascript-comparisons) – Dániel Kis Nov 05 '16 at 07:29

3 Answers3

2

In Javascript, === do not try to coerce the type of the variables you are testing, while == will do its best to 'typecast' those variables if needed to compare them.

For instance 1 == '1' returns true, while 1 === '1' returns false since you are comparing a number to a string.

Lastly, jQuery and pure javascript both uses the same === and == operators. Hence, there will not be any difference between the two.

The MDN documentation is pretty good too.

Alex
  • 1,241
  • 13
  • 22
2

The == operator will compare for equality after doing any necessary type conversions. The === operator will not do the conversion, so if two values are not the same type === will simply return false. Both are equally quick.
For more you can check this answer in stack oveflow
Which equals operator (== vs ===) should be used in JavaScript comparisons?

Community
  • 1
  • 1
Rajesh Patel
  • 1,946
  • 16
  • 20
2

There is a slight difference between == and === operators. If you are using == that means you are comparing just values for example (5=='5') will return you true whereas first operand is integer and the second operand is string.Now considering the same example with === i.e (5==='5') will return you false because the '===' operator will check the value as well as type conversion and in this case integer cannot be equal to the string. Hope this helps you.

Zohra Gadiwala
  • 206
  • 1
  • 4
  • 17