Equivalent operators in js (differences between Abstract equal = and strict equal =)

Source: Internet
Author: User

In JavaScript, equality operators in JavaScript are classified into abstract equality and strict equality. What are their differences. Before describing a specific algorithm, we should first mention the JS data type. JS data types are divided into six categories: Undefined Null String Number Boolean Object. here, we use Type (x) to represent the Data Type 1 of x, and the process of abstracting equal = x = y is as follows: 1, Type (x) and Type (y) same: If Type (x) is Undefined or Null, true is returned, I .e.: undefined = undefined; null = null returns true if Type (x) is Number, if x or y is NaN, false is returned, that is, NaN = NaN is false; x and y are equal, or-0 and + 0 both return true, otherwise, false is returned. If Type (x) is String, true is returned only when the characters at the positions of x and y are identical. Otherwise, false is returned. If Type (x) is Boolean, true is returned for the same value. Otherwise, false. If Type (x) is an Object True is returned for the same reference. Otherwise, false is returned. For example: var a = {m: 1} var B = {m: 1} a = B. The result is false because, B is not the same reference. Let's look at var a = {m: 1} B = a = B. The result is true because they reference the same object 2, Type (x) is Undefined, Type (y) is Null, return true, that is, undefined = null is true 3, Type (x) is String, Type (y) is Number, convert x to Number, and then compare. For example: 1 = "1", the result is true, because after "1" is converted to Number, it is 1 4, Type (x) if it is Boolean and Type (y) is Number, convert x to Number for comparison. For example, true = 1; false = 0; true 5, Type (x) string or Number, Type (y) is Object, convert y to basic value, Example: 1 = new String ("1") "2" = new Number (2) results in true 6, returns false2, strictly equal = 1, if the result of Type (x) and Type (y) is inconsistent, false is returned, that is, if the Type is different, false is returned. For example: 1 = "1" false undefined = null false2, if Type (x) is Number, if x or y is NaN, false is returned, that is: naN = NaN: false; returns true if x and y are equal or if-0 and + 0 are both equal; otherwise, returns false3. If Type (x) is Undefined, returns true. If the result of Type (x) is Null, returns true. If Type (x) is String, returns true only when the characters at the corresponding positions of x and y are identical, otherwise, false is returned. If Type (x) is Boolean, true is returned for the same value. Otherwise, false is returned. If Type (x) is an Object, true is returned for the same reference. Otherwise, false is summed up. The difference between strict equality and abstraction is that strict equality first requires the same Type, during the comparison process, no type conversion is performed, and the comparison object type is converted to the same type before being compared.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.