Possible Duplicate:
JavaScript === vs == : Does it matter which “equal” operator I use?
Noticed this
== is bad. Don’t ever use it. On everything else about the language, you’ll run into differing opinions.
…while reading an article I found on Hacker News: http://duruk.net/some-web-development-tips/
Why is this frowned upon? What are the alternatives? Is this wrong…
if (foo == bar) {
//do something
}
In general, it’s better to use
===and!==. These compare type and value and do not do type conversion.Whereas
==will do a type conversion of one to match the other and then do the comparison so it might report equality on things that are not really the same.For example: