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

Source: Internet
Author: User

After reading ext's Source code 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>

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.