[to] the difference between = = = (equals) and = = = (constant equals) in JavaScript

Source: Internet
Author: User

Haven't been paying attention to this operator that is constant equal to (three equals: = = =). Later in the actual work encountered, just want to know what is equal and constant equals what is the difference.

JavaScript is a weakly typed language, which means that the equals operator enforces type conversions in order to compare two of values. Note the equality operation for 0, for example:

JS Code
  1. "= =" 0 "//False
  2. 0 = = ""//True
  3. 0 = = "0"//True
  4. False = = "false"//False
  5. false = = "0"//True
  6. false = = undefined//False
  7. false = = NULL//False
  8. NULL = = undefined//True
  9. "\t\r\n" = = 0//True

Instead of the normal equals operator, the coercion type conversion is not performed. In this case, the results are not quite the same:

JS Code
  1. "" = = = "0"//False
  2. 0 = = = ""//False
  3. 0 = = = "0"//False
  4. false = = = "false"//False
  5. false = = = "0"//False
  6. false = = = undefined//False
  7. false = = = NULL//False
  8. NULL = = undefined//False
  9. "\t\r\n" = = = 0//False

The object, when used as constant equals, is used to determine whether the same object is equal to the judgment value. So, pay attention to it later. Try to use constant equals when judging, so you don't have to make a forced conversion comparison

[to] the difference between = = = (equals) and = = = (constant equals) in JavaScript

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.