False values in JavaScript and their common comparison operations

Source: Internet
Author: User

1. Value of Ture or False

The value of the Boolean type that will be implicitly converted to false in the If judgment has false, 0, undefined, null, ' ', NaN (not a number)

Besides the other values will be considered true, including ' 0 ', ' false ', empty function, empty array ([]), Empty object ({})

var a =!! (0);//equivalent to var a = False;var a =!! (' 0 '); Equivalent to var a = true;

2. Comparison of Falsy values

The value is false, ', 03 is the value comparison, as follows:

Alert (false = = ");//truealert (false = = 0);//truealert (0 = =");//true

False, ", 0, compared to undefined, NULL, the result is as follows:

Alert (false = = undefined);//falsealert ("= = null);//falsealert (" = = = undefined);//false

 

alert (undefined = = undefined);//truealert (null = = null);//true

As you can see,0, ', false, the three values are equal, Undefinde, and Null is different from any other type of value compared to itself.

The comparison between Nan and other types of falsy values is as follows:

Alert (false = = Nan);//falsealert (0 = = Nan);//falsealert ("= = Nan);//falsealert (undefined = = Nan);//falsealert (null = = Nan);//falsealert (nan = = nan);//false

The result is thatnan is not equal to any type of value, including itself . How to determine the value of a Nan type

Alert (typeof (Nan));//numberalert (IsNaN (Nan));//true

  

False values in JavaScript and their common comparison operations

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.