Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between the Object.is () and the = operators in JavaScript

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report