行と列はそれぞれ左辺と右辺を表し、比較の結果true
が返される組み合わせを○で、false
の場合を×で表します。
論理値 | 数値 | 文字列 | null | 配列 | オブジェクト | NaN | undefined | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
true | false | 1 | 0 | -1 | '1' | '0' | '-1' | 'abc' | '' | [] | {} | ||||
true | ○ | × | ○ | × | × | ○ | × | × | × | × | × | × | × | × | × |
false | × | ○ | × | ○ | × | × | ○ | × | × | ○ | × | ○ | × | × | × |
1 | ○ | × | ○ | × | × | ○ | × | × | × | × | × | × | × | × | × |
0 | × | ○ | × | ○ | × | × | ○ | × | × | ○ | × | ○ | × | × | × |
-1 | × | × | × | × | ○ | ○ | × | ○ | × | × | × | × | × | × | × |
'1' | ○ | × | ○ | × | ○ | ○ | × | ○ | × | × | × | × | × | × | × |
'0' | × | ○ | × | ○ | × | × | ○ | × | × | × | × | × | × | × | × |
'-1' | × | × | × | × | ○ | ○ | × | ○ | × | × | × | × | × | × | × |
'abc' | × | × | × | × | × | × | × | × | ○ | × | × | × | × | × | × |
'' | × | ○ | × | ○ | × | × | × | × | × | ○ | × | ○ | × | × | × |
null | × | × | × | × | × | × | × | × | × | × | ○ | × | × | × | ○ |
[] | × | ○ | × | ○ | × | × | × | × | × | ○ | × | ○ | × | × | × |
{} | × | × | × | × | × | × | × | × | × | × | × | × | ○ | × | × |
NaN | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × |
undefined | × | × | × | × | × | × | × | × | × | × | ○ | × | × | × | ○ |
論理値 | 数値 | 文字列 | null | 配列 | オブジェクト | NaN | undefined | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
true | false | 1 | 0 | -1 | '1' | '0' | '-1' | 'abc' | '' | [] | {} | ||||
true | ○ | × | × | × | × | × | × | × | × | × | × | × | × | × | × |
false | × | ○ | × | × | × | × | × | × | × | × | × | × | × | × | × |
1 | × | × | ○ | × | × | × | × | × | × | × | × | × | × | × | × |
0 | × | × | × | ○ | × | × | × | × | × | × | × | × | × | × | × |
-1 | × | × | × | × | ○ | × | × | × | × | × | × | × | × | × | × |
'1' | × | × | × | × | × | ○ | × | × | × | × | × | × | × | × | × |
'0' | × | × | × | × | × | × | ○ | × | × | × | × | × | × | × | × |
'-1' | × | × | × | × | × | × | × | ○ | × | × | × | × | × | × | × |
'abc' | × | × | × | × | × | × | × | × | ○ | × | × | × | × | × | × |
'' | × | × | × | × | × | × | × | × | × | ○ | × | × | × | × | × |
null | × | × | × | × | × | × | × | × | × | × | ○ | × | × | × | × |
[] | × | × | × | × | × | × | × | × | × | × | × | ○ | × | × | × |
{} | × | × | × | × | × | × | × | × | × | × | × | × | ○ | × | × |
NaN | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × |
undefined | × | × | × | × | × | × | × | × | × | × | × | × | × | × | ○ |
NaNは、演算子による比較ではつねにfalseを返します。よってそれがNaNであるか判定するには、isNaN()を用いるか、自身と比較 (a != a
) します。NaN - JavaScript | MDN
次に示すコードで検証しました。
var x; var data = [ true, false, 1, 0, -1, '1', '0', '-1', null, [], {}, 'abc', '', 0/0, x ]; for( var k = 0; k < data.length; k++ ) { document.write( data[ k ] + ',' ); for( var i = 0; i < data.length; i++ ) { document.write( data[ k ] == data[ i ]? 'o' : 'x' ); document.write( ',' ); } document.writeln( '' ); }