It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center
                            
                        
                    
                
                                7年前关闭。
            
                    
我想拥有所有值的列表,这些值将通过相等性检查如truefalse甚至!=评估为==if()

我有一份过去几年收集的清单,但由于我的电脑而死了

最佳答案

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

“最好学习强制性规则,而不是试图记住上帝知道多少不同比较结果”。

...但是这是清单;)

==

""           ==   "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


===

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


对象

{}                 === {};       // false
new String('foo')  === 'foo';    // false
new Number(10)     === 10;       // false

var foo = {};
foo                === foo;      // true

NaN                ==   NaN      // false
NaN                ===  NaN      // false
NaN                ==   false    // false

//NaN does not coerce using non-strict equality.


更新29/01/14:

为完整起见添加了NaN

关于javascript - 没有严格的比较,哪些值将被评估为真和假? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9417201/

10-12 00:06