Fake values in JavaScript

Source: Internet
Author: User

Generally, in the following statement structure, you need to determine whether the if branch statement is true or false. The second statement in the while LOOP statement for is like if (boo) {// do something} while (boo) {// do something} the six values in JavaScript are "false". These six values are falsenullundefined0'' (Null String) NaN. Here, false is a boolean type, the other five are not. In addition to these six, all others are "true", including objects, arrays, regular expressions, and functions. Note that '0', 'null', 'false', {}, and [] are also true values. Although these six values are both false, they are not all equal. Console. log (false = null) // falseconsole. log (false = undefined) // falseconsole. log (false = 0) // trueconsole. log (false = '') // trueconsole. log (false = NaN) // false console. log (null = undefined) // trueconsole. log (null = 0) // falseconsole. log (null = '') // falseconsole. log (null = NaN) // false console. log (undefined = 0) // falseconsole. log (undefined = '') // falseconsole. log (undefined = NaN) // false console. log (0 = '') // trueconsole. log (0 = NaN) // false for "=", the preceding conclusion is as follows: false is not only true compared with itself, but also 0, ''is true only when truenull is compared with undefined. In turn, undefined is true only when it is compared with null, and no second 0 is compared with true if it is not set to false, there is also an empty string ''null string'' which is equal to true and false, and there is 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.