2

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
}
Community
  • 1
  • 1
alt
  • 13,357
  • 19
  • 80
  • 120

1 Answers1

4

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:

"0" == 0   // true
"0" === 0  // false
jfriend00
  • 683,504
  • 96
  • 985
  • 979