=== 不轉(zhuǎn)類型鸽疾,+0===-0NaN!==NaN used by Array.prototype.indexOf, Array.prototype.lastIndexOfcase-matching 是啥??
SameValueZero used by Map and SetArray.prototype.includes[NaN].includes(NaN)[+0].includes(-0)
mdn上還有String.prototype.includes 但是這個(gè)會(huì)先對(duì)參數(shù)先轉(zhuǎn)string
還有些不常用的
SameValue: used in all other places 值相等 Object.is
type
+0 -0
NaN
==
等
不等
===
等
不等
SameValueZero
等
等
SameValue
不等
等
js提供的 三種判斷
=== Strict Equality
== Abstract Equality
Object.is SameValue ES2015新增(es6)
var a = {valueOf(){return 1}}
var b = {valueOf(){return 1}}
var c = {toString(){return '1'}}
var d = {toString(){return '1'}}
console.log(a == 1)
console.log(a == '1')
console.log(b == 1)
console.log('a == b' ,a == b) // false
console.log('c == d' ,c == d) // false
// === 判斷類型邪意、NaN不等NaN (The only case in which (x !== x) is true is when x is NaN)
// Object.is 其他和===類似 但是 NaN等NaN +0不等-O
// Object.is ES2015新增
console.log('NaN == NaN', NaN == NaN) // false
console.log('NaN === NaN', NaN === NaN) // false
console.log(Object.is(NaN, NaN))
console.log(+0 === -0)
console.log('Object.is(+0, -0)', Object.is(+0, -0)) // false