3

Possible Duplicate:
Why does ('0' ? 'a' : 'b') behave different than ('0' == true ? 'a' : 'b')

'0' == false; // true

'0' || 1; // '0'

'0' ? true : false; // true

!!'0' // true

Is "==" will cast '0'-> 0 -> false, but other don't?

I want more detail.

Community
  • 1
  • 1
p2world
  • 39
  • 1
  • 3
  • 5
    Have you made any effort to *search* for more detail? This is the subject of a million and one internet articles on JavaScript. – Kerrek SB Dec 24 '11 at 08:49
  • 2
    I attempted to Google this myself, but couldn't find any reason why `'0'` acts differently near `==`. It's a bitch Googling "=="... – Hubro Dec 24 '11 at 09:26

1 Answers1

7

Javascript truth table for you.

''        ==   '0'           // false
0         ==   ''            // true
0         ==   '0'           // true
false     ==   'false'       // false
false     ==   '0'           // true
false     ==   undefined     // false
false     ==   null          // false
null      ==   undefined     // true
" \t\r\n" ==   0             // true

Give it a try and you will be able to remove your confusion I think.

Lion
  • 18,729
  • 22
  • 80
  • 110