Object.is()
语法
is(value1: any, value2: any): boolean;
描述
用于判断两个值是否相同,返回一个 Boolean 类型的值。
TIP
该方法和
全等运算符仅有两个不同。
===运算符将-0和+0视为相等,而Object.is(-0, +0)返回false
===运算符将NaN和NaN视为不相等,而Object.is(NaN, NaN)返回true
示例
// 特例
;+0 === -0 // true
Object.is(+0, -0) // fasle
// 特例
NaN === NaN // fasle
Object.is(NaN, NaN) // true
undefined === undefined // true
Object.is(undefined, undefined) // true
null === null // true
Object.is(null, null) // true
true === true // true
Object.is(false, false) // true
Object.is(window, window) // true