Differences between "= =" and "= = =" Operators in JavaScript

Source: Internet
Author: User

Same point:

Two operators can be used to compare two values for equality, allow manipulation of any type of operand, or return true if the operands are equal, otherwise false.

Different points:

the "= = =" operator, also known as the strict equality operator, is used to detect whether two operands are strictly equal. The operator first calculates the value of its operand, then compares the two values, and does not first convert any type of operator into the comparison process.

the "= =" operator, called the equality operator, is used to detect whether two operands are equal, where the definition of "equality" is very loose and allows for type conversions. The equality operator "= =" and the "= = =" operator are similar, but the comparison of equality operators is not strict. If the two operands are not of the same type, the equality operator attempts to perform some type conversions on the operands and then compares them. For example:

1. If one value is null and the other is undefined, they are equal.

2. If one value is a number and the other is a string, the comparison now converts the string to a number and then compares it with the converted value.

3. If one of the values is true, convert it to 1 and then compare.

Use case:

Because the "= =" will occur during the use of the type conversion, so in order to avoid the use of "= =" in the process of unexpected type conversion and affect the results of the comparison, it is recommended that except for special cases, all use "= = =".

Note: This article for their own learning to use the JS process of learning notes, the article describes if there are improper, welcome to master shot Bricks.

Differences between "= =" and "= = =" Operators 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.