What is the difference between the Object.is () and the = operators in JavaScript
This article mainly introduces the relevant knowledge of "What is the difference between Object.is() and === operator in JavaScript". Xiaobian shows you the operation process through actual cases. The operation method is simple and fast, and the practicality is strong. I hope this article "What is the difference between Object.is() and === operator in JavaScript" can help you solve the problem.
In short, the double equals operator (==) only compares values, while the triple equals operator (===) compares values and types. But there is a third option, Object.is (), which behaves the same as the three-equals operator except for NaN,+0 and-0.
The following are some examples that further clarify:
{} === {}; // false Object.is({}, {}); // false 1 === 1; // false Object.is(1, 1); // false +0 === -0; // true Object.is(+0, -0); // false NaN === NaN; // false Object.is(NaN, NaN); // true
The following code simulates the Object.is implementation in ES5:
Object.defineProperty(Object, 'is', { value: function(x, y) { if (x === y) { //For cases where +0 is not equal to-0 return x !== 0 || 1 / x === 1 / y; } //for NaN return x !== x && y !== y; }, configurable: true, enumerable: false, writable: true }); about "JavaScript Object.is() and === operator what is the difference" content introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.