The difference between JavaScript = and =: javascript

Source: Internet
Author: User

The difference between JavaScript = and =: javascript
Differences between JavaScript = and =

==And === both determine whether the variables on both sides are equal, but there are also differences

I. =

===Indicates a constant. First, compare whether the data types of variables on both sides are equal, and then compare whether the values of variables on both sides are equal;

  • Var param1 = '1', param2 = '1 ';
    Param1 = param2; // The type and value are both equal to true
    Var param3 = 1;
    Param1 = param3; // The type is not equal to the value. false
    Var param4 = 2;
    Param1 = param4; // The type and value are not equal. false

  • Var param1 = null, param2 = undefined;
    Param1 = param2; // false

2. =

= Equal means that only the values of the variables on both sides are equal

  • Var param1 = '1', param2 = '1 ';
    Param1 = param2; // The type and value are both equal to true
    Var param3 = 1;
    Param1 = param3; // The type is not equal and the value is true.
    Var param4 = 2;
    Param1 = param4; // The type and value are not equal. false

  • Var param1 = null, param2 = undefined;
    Param1 = param2; // true

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.