现在ES6又加了一个Object.is,让比较运算的江湖更加混乱。
多数情况下Object.is等价于“===”,如下
1 === 1 // trueObject.is(1, 1) // true "a" === "a" // trueObject.is("a", "a") // true true === true // trueObject.is(true, true) // true null === null // trueObject.is(null, null) // true undefined === undefined // trueObject.is(undefined, undefined) // true但对于NaN、0、+0、 -0,则和 “===” 不同
NaN === NaN // falseObject.is(NaN, NaN) // true 0 === -0 // trueObject.is(0, -0) // false -0 === +0 // trueObject.is(-0, +0) // false以上就是关于Javascript ES6新增值比较函数Object.is的全部内容,希望对大家的学习工作能有所帮助。