If the two values are of the same type, then it’s OK. Otherwise it forces a type coercion, meaning it tries to convert the two variables to the same type, in order for it to be able to compare them. This automatic forced conversion might be wrong, in which case your code will be wrong and the functionality you’ve implemented will be wrong.
The best way to check two values is to use the strict equal (“===”) and strict not equal (“!==”) operators. These operators verify if the two variables are of the same type AND if their values are equal/not equal.
Regarding the equality operators, it writes:
The problem with the double-equals operator is that the interpreter will make great efforts to coerce the two values being compared into the same type so that they can then be compared. It’s a "lazy" comparison, not for the interpreter, but for the programmer. The triple-equals operator is much more rigorous — it checks the type to be equal too.
Let’s see some examples. If you run this set of statements in Firebug within Firefox, they’ll all print true:
The rules for why these all evaluate as true are simple enough, but my recommendation is don’t rely on ==. For example, check out the last two statements. Since the empty string equals 0 and 0 equals the string ‘0’, then it must imply that ” == ‘0’. Sorry, nice try, but no it doesn’t. Since == can produce examples where the operator is not transitive, against all common logic, that’s a reason not to use it in my book. Stick to === and !==, that’s my advice.
More explanations as to why === and !== is better, you can read here: http://msmvps.com/blogs/luisabreu/archive/2009/08/25/vs.aspx