console.log(Infinity === Infinity) // true
console.log(Infinity === 1 / 0) // true
console.log(-Infinity === -1 / 0) // true
console.log(Infinity === -Infinity) // false
console.log(Object.is(Infinity, Infinity)) // true
console.log(Object.is(Infinity, 1 / 0)) // true
console.log(1 / -Infinity); // -0
console.log(-1 / Infinity); // -0
console.log(NaN===NaN) // false
console.log(NaN===0/0) // false
console.log(Object.is(NaN, NaN)); // true
console.log(Object.is(NaN, 0/0)); // true
console.log(Object.is(NaN, 1/0)); // false
console.log(-0) // -0
console.log(0 === -0) // true
console.log(Object.is(0, -0)); // false
console.log(Object.is(0, +0)); // true
console.log(Object.is(-0, -0)); // true
console.log(undefined === void 0) // true, void 运算符能对给定的表达式进行求值,然后返回 undefined
if (!Object.is) {
Object.is = function(x, y) {
// SameValue algorithm
if (x === y) { // Steps 1-5, 7-10
// Steps 6.b-6.e: +0 != -0
return x !== 0 || 1 / x === 1 / y;
} else {
// Step 6.a: NaN == NaN
return x !== x && y !== y;
}
};
}
网友评论