js 相等判断
===
==
Number
1 == '1.00' // true
// Equivalent to 1 == Number(`1.00`)
1 == true // true
// Equivalent to 1== Number(true)
aa = {
toString: () => 2,
valueOf:() => 1
}
1 == a // true
// Equivalent to 1 == aa.valueOf()
aa = {
toString: () => 1,
valueOf:() => 2
}
1 == a // false
// Equivalent to 1 == aa.valueOf()
String
'1.00' == true // true
// Equivalent to Number('1.00') == Number(true)
aa = {
toString: () => 2,
valueOf:() => 1
}
'1.00' == aa; // true
// Equivalent to
// 1. '1.00' == aa.valueOf();
// 2. Number('1.00') == 1
// 先 取 valueOf 返回值不是原始值 继续取 toString();
aa = {
toString: () => 1,
valueOf:() => ({})
}
'1.00' == aa; // true
// Equivalent to
// 1. '1.00' == aa.valueOf();
// 2. Number('1.00') == aa.toString()
Object.is
Object.is(NaN,NaN) // true