Skip to content Skip to sidebar Skip to footer

What Values Are Evaluated To True And False Without Strict Comparasion?

I want to have a list of all values that will be evaluated to true or false with poor equality check like !=, == or even if() I had one list that I collected throught years, but it

Solution 1:

http://bonsaiden.github.com/JavaScript-Garden/#types.equality

"It's better to learn the coercion rules rather than try to memorize the results of god knows how many different comparisons"...

...But here's a list ;)

==

""           ==   "0"           // false0            ==   ""            // true0            ==   "0"           // truefalse        ==   "false"       // falsefalse        ==   "0"           // truefalse        ==   undefined     // falsefalse        ==   null          // falsenull         ==   undefined     // true" \t\r\n"    ==   0             // true

===

""           ===   "0"           // false0            ===   ""            // false0            ===   "0"           // falsefalse        ===   "false"       // falsefalse        ===   "0"           // falsefalse        ===   undefined     // falsefalse        ===   null          // falsenull         ===   undefined     // false" \t\r\n"    ===   0             // false

Objects

{}                 === {};       // falsenewString('foo')  === 'foo';    // falsenewNumber(10)     === 10;       // falsevar foo = {};
foo                === foo;      // trueNaN                ==   NaN      // falseNaN                ===  NaN      // falseNaN                ==   false// false//NaN does not coerce using non-strict equality.

Update 29/01/14:

Added NaN for completeness.

Post a Comment for "What Values Are Evaluated To True And False Without Strict Comparasion?"