Anyone coming from a language like C that doesn’t have a === operator seems shocked when they encounter such a ludicrous operator. For them, and for anyone being a bit careless, simple usage of === can really bite you.
Here’s something that happened to me. It was in more abstracted code than this, but this boils it down to just what was going on:
var str:Object = "3"; var str2:Object = "" + 3; var num:Object = 3; trace(str == num); trace(str === num); trace(str == str2); trace(str === str2);
Care to guess what booleans get printed? It would seem that the first and second should not be true as this is a comparison not only of two different objects but between two different types: String and int. However, the magic of the == operator comes into play in the first case and converts types such that the string and the int represent the same value and true is returned. The === operator in the second case prevents this conversion and false is returned. In both the third and fourth cases the types are both String so no conversion is necessary. Even though they occupy separate memory space since both are not the same string literal they are compared character-by-character and true is returned in both cases. Here are the answers for your reference:
var str:Object = "3"; var str2:Object = "" + 3; var num:Object = 3; trace(str == num); // true trace(str === num); // false trace(str == str2); // true trace(str === str2); // true
I hope this helps you understand a bit more about == and === so that you’ll know which to use when you want to be strict and which to use when you want the more “magical” features.