Abdul Rahman Abdul Rahman - 1 month ago 17
Javascript Question

jQuery/Javascript the comparison operators "===" and "=="

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?

Answer

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.