In JavaScript! =, = ,! The usage and difference of ====.

Source: Internet
Author: User

In JavaScript! =, = ,! The usage and difference of ====.
var num = 1;    var str = '1';    var test = 1;    test == num  // True; same type; Same Value   test === num // True; same type; Same Value   test !== num // False test and num are of the same type, and their values are the same. Non-calculation is certainly false.   num == str  // True converts str to a number and checks whether it is equal.   num != str  // Non-operation with false =   num === str // If the type of false is different, false is returned directly.   num !== str // True num and str are of different types, which means they are not equal to each other. The non-operation is true. 

= And! = If the comparison type is different, first try the conversion type, then compare the value, and finally return the comparison result.

While

===And! = The value is compared only in the same type. (Compare when values and types are the same)
 

=, When the value types on both sides are different, type conversion should be performed first and then comparison should be made.

===, No type conversion is required. The types may vary.

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.