null, undefined, 0, False, "" who Equals who

Source: Internet
Author: User

JavaScript is such a weak type of language, in the judgment of equality is very troublesome, obviously not a thing, but equal. This example shows the equality of NULL, undefined, 0, false, and "". var arr = [null, undefined, 0, false, "];
var str = "";
for (var i = 0; i < arr. length; i++)
{
for (var j = i + 1; j < arr. length; j + +)
{
if (arr[i] = = Arr[j])
{
str = Arr[i] + "= =" + ((J!= 4)? ARR[J]: "\" \ "") + "\ n";
}
Else
{
str = arr[i] + "!=" + ((J!= 4)? ARR[J]: "\" \ "") + "\ n";
}
}
}

Result NULL = = undefined
Null!= 0
Null!= False
Null!= ""
Undefined!= 0
Undefined!= false
Undefined!= ""
0 = False
0 = ""
false = = ""

It can be seen that null and undefined are in a gang, and 0, False, "" is another gang.

How to eliminate interference.

Because of the different data types are waiting, to eliminate interference, such as let 0 not equal to "", how to do it. with identity = = = or!==. So that they are not equal to anyone else.

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.