Examples of false values for exotic flowers in JavaScript application of _javascript techniques

Source: Internet
Author: User
Usually in the following statement structure to determine the true and false

If branch statement
While Loop statement
For the second statement in the

Such as
Copy Code code as follows:

if (boo) {
Do something
}

while (Boo) {
Do something
}

6 values in JavaScript are "false" and the six values are

False
Null
Undefined
0
' (empty string)
NaN

In this case, false itself is a Boolean type, and the other 5 are not.

In addition to these 6, the other is "true", including objects, arrays, regular, functions, and so on. Note that ' 0 ', ' null ', ' false ', {}, [] are also true values.

Although these six values are "false", they are not all equal
Copy Code code as follows:

Console.log (false = null)//False
Console.log (false = = undefined)//False
Console.log (false = = 0)/True
Console.log (false = = ")//True
Console.log (false = NaN)//False

Console.log (null = = undefined)//True
Console.log (Null = = 0)//False
Console.log (Null = = ")//False
Console.log (null = NaN)//False

Console.log (undefined = = 0)//False
Console.log (undefined = = ")//False
Console.log (undefined = = NaN)//False

Console.log (0 = = ")//True
Console.log (0 = NaN)//False

for "= =", the above conclusions are drawn as follows

False, and 0, ' is true in addition to comparing itself to true
Null is true when compared to undefined, and in turn undefined is only null compared to true, without a second
0 In addition to false compared to true, there is also an empty string '
Null string ' out and false compared to true, there is also a number 0
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.