The difference between = and = in JavaScript (interview question) and javascript interview

Source: Internet
Author: User

The difference between = and = in JavaScript (interview question) and javascript interview

= Used for general comparison, = used for strict comparison;
= The data type can be converted during comparison, === strict comparison, as long as the type does not match, flase is returned.

Example:
"1" = true; // true
Different types, "=" will first convert the type, convert true to 1, that is, "1" = 1;

At this time, the type is still different, continue type conversion, convert "1" to 1, that is, 1 = 1;

At this time, "=" both the left and right types are numeric, and the comparison is successful!


If the comparison is: "1" = true, the left side is the boolean type, the right side is the boolean type, the left side is different, and the result is false;

If the comparison is: "1" = 1, the left side is the numeric type, the right side is the int numeric type, the left side is different, and the result is false;

If the comparison is: 1 = 1, the left side is the int numeric type, the right side is the int numeric type, the left side is the same type, the value size is the same, and the result is true;

If the comparison is: 1 = 2, the left side is the int numeric type, the right side is the int numeric type, the left side is the same type, but the value size is different, the result is false;

In short, "=" only requires equal values; "=" requires equal values and types

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.