quote:
Originally posted by deAd
Cookie, why do you use the === operator as opposed to ==? What difference does it make in this case?
=== and !== are identity operators.
== and != are equality operators.
It is preferred to use identity operators as this gives you a warning with wrong type casting and it is faster because JScript doesn't need to convert the variables first to the same type. It also reduces possible errors you otherwise might not notice so quickly.
The identity operators (=== and !==) compare the content of the variables.
The equality operators (== and !=) compare the content of the variables and the type by first converting the variables to a general type.
Moral:
Always use the identity operators (=== and !==) when you compare two variables of the same type. eg: when comparing strings or characters.
Thus always use the identity operators (=== and !==) whenever you can and only use equality operators (== and !=) if you really really need to.
for details, see:
CookieRevised's reply to Nudges, Updated.
CookieRevised's reply to How do I declare this?
eg:
if you compare two variables of the same type, like a string with a string, like in the script example in my previous post, it makes much better sense to use the identity operator (===) than the equality operator (==) because you know both variables are strings.
eg:
"5" == 5 is true, eventhough one is a string type and the other is a number.
"5" === 5 is false, since they are not of the same type.