About constant equals (= = =) and non-constant Equals (!==) _javascript tips

Source: Internet
Author: User
In looking at Ext source code, encountered "= = =" and "!==" of the writing, temporarily puzzled, in the group of information, only to know what they represent the meaning.
Oh, it seems to have a network is really convenient:
Reference
• constant equals (= = = = Check whether two operands are the same, that is, check that the values of operands that do not have data type conversions are equal.)
• Non-constant Equals (!==): Check that the value of two operands is not the same as before data conversion.
The following is an excerpt from the discussion chat record:

Maple Rock 09:24:01
if (index!==-1) {
...
}

What does that mean? Who knows?
Road Pedestrian 09:26:32
= = = = Constant equals.
Road Pedestrian 09:26:41
!== is not constant equal to.
Maple Rock 09:33:58
Oh, according to the road pedestrian said "constant equals" search under:

3. Use constant equals and non-constant equals operators (= = = and!===)
1 Strictly compare the value of two variables is equal, do not do any conversion work, such as 2=== "2" is not tenable, return false
Maple Rock 09:34:13
<script type= "Text/javascript" >
<!--
Alert (2== "2");
Alert (2=== "2");
Alert (2!== "2");
-->
</script>
Maple Rock 09:36:32
Hey, this detailed point:
• constant equals (= = = = Check whether two operands are the same, that is, check that the values of operands that do not have data type conversions are equal.)
• Non-constant Equals (!==): Check that the value of two operands is not the same as before data conversion.
Road Pedestrian 09:39:41
What does the IF (index!==1) mean ... Maple Rock??
Maple Rock 09:43:04
Index!==1
Equivalent:
! (index===1)
Maple Rock 09:43:10
It's supposed to be like this.
Maple Rock 09:43:18
I'll give it a try.
Maple Rock 09:44:07
<script type= "Text/javascript" >
<!--
var a = (2!== "2");
var B =! (2=== "2");
Alert (A = = = B);
-->
</script>
Maple Rock 09:44:40
The comparison of 2=== "2" also requires the same data type
Maple Rock 09:44:45
Before returning to the true
Z 09:49:30
= = = This is the case
Z 09:49:44
If the two values have different types, they are not identical.
Z 09:51:52
= = should be to convert two numbers to char and compare values
= = = Whether to compare the same type first
Maple Rock 09:54:42
Tested it, and it did.
<script type= "Text/javascript" >
<!--
var O1 = {A: "a"};
var O2 = o1.tostring ();
alert (O1==O2);
alert (O1===O2);
-->
</script>

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.