About constant equals (=) and non-constant equals (! =)

Source: Internet
Author: User

When you look at the Ext source code, you may encounter "=" and "! = "For a moment, I cannot understand the meaning of each of them.
Haha, it seems that there is a network that is really convenient :)
Reference
· Constant equals (=): checks whether the two operands are the same, that is, checks whether the values of the operands without data type conversion are equal.
· Non-constant equals (! =): Check whether the values of the two operands are different before data conversion.
The following is an excerpt from the discussion record:

Fengyan 09:24:01
If (index! =-1 ){
...
}

What does it mean? Who knows?
Pedestrians on the road 09:26:32
=== Constant equals ..
Pedestrians on the road 09:26:41
! = Not constant equals ..
Fengyan 09:33:58
Haha, according to the "constant equals" of pedestrians on the road, I searched:

3. Use the constant equals and non-constant equals operators (= and! ===)
1) check whether the values of the two variables are equal and do not perform any conversion. For example, if 2 = "2" is not true, false is returned.
Fengyan 09:34:13
<Script type = "text/javascript">
<! --
Alert (2 = "2 ");
Alert (2 = "2 ");
Alert (2! = "2 ");
// -->
</Script>
Fengyan 09:36:32
Hey, here's the details:
· Constant equals (=): checks whether the two operands are the same, that is, checks whether the values of the operands without data type conversion are equal.
· Non-constant equals (! =): Check whether the values of the two operands are different before data conversion.
Pedestrians on the road 09:39:41
If (index! = 1) What does it mean ??
Fengyan 09:43:04
Index! = 1
Equivalent:
! (Index = 1)
Fengyan 09:43:10
This should be the case.
Fengyan 09:43:18
Try me
Fengyan 09:44:07
<Script type = "text/javascript">
<! --
Var a = (2! = "2 ");
Var B =! (2 = "2 ");
Alert (a = B );
// -->
</Script>
Fengyan 09:44:40
2 = "2" requires the same data type
Fengyan 09:44:45
Returns true
Z 09:49:30
Yes
Z 09:49:44
If the two values have different types, they are not identical.
Z 09:51:52
= Convert both numbers into CHAR and then compare the values.
===Is to first compare whether the types are the same
Fengyan 09:54:42
The test is true.
<Script type = "text/javascript">
<! --
Var o1 = {a: ""};
Var o2 = o1.toString ();
Alert (o1 = o2 );
Alert (o1 = o2 );
// -->
</Script>

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.