<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>生の値とオブジェクトの等価比較</title>
</head>
<body>
<script>
let a = [];
let b = "0";
// 1
console.log(a==0); // true
// 2
console.log(a==!a);// true
// 3
console.log(a==b); // false
// 4
console.log(b==0); // true
// eg 1
console.log(Number([])); // 0
// eg 2
console.log(Boolean([])); // true
// eg 3
console.log(String([])); // ''
// eg 4
console.log(Number(b)); // 0
/*
js偽の値:false、null、undefined、null文字、0、NaNのみ、それ以外のbooleanに変換された値はすべて真となる
*/
console.log(null == 0); // false
console.log(null<0); // false
console.log(null<=0); // true
// 等価性を比較するために、nullやundefinedは他の値に変換できない。undefinedやnullなどの数値は、等価判定を行う際に型変換されないということだ。
// null == undefined,これはその通りだが、関係演算子は変換できる。
// 1もしxが正常な値でなければ、実行を中断する。
// 2もしyが正常な値でなければ、実行を中断する。
// 3もしTypeがTypeと同じなら、厳密な等価演算を行う。=== y。
// 4xがNULLでyが未定義の場合は真を返す。
// 5xが未定義でyがNULLの場合は真を返す。
// 6Typeが数値でTypeが文字列の場合、xを返す。== ToNumber(y)の結果は
// 7Typeが文字列でTypeが数値の場合、ToNumberを返す。== yの結果は
// 8Typeがbooleanの場合、ToNumberを返す。== yの結果は
// 9もしTypeがbooleanなら、xを返す。== ToNumber(y)の結果は
// 10もしTypeが文字列か数値かSymbolで、Typeがオブジェクトなら、xを返す。== ToPrimitive(y)の結果は
// 11もしTypeがオブジェクトで、Typeが文字列か数値かシンボルであれば、ToPrimitiveを返す。== yの結果は
// 12は偽を返す。
</script>
</body>
</html>
バムの金時豆への道によって
主要業務:フロントエンド開発
*** 生の値とオブジェクトの等価性の比較





