True and false of values in JavaScript

Source: Internet
Author: User

The values for Flase are:

False0  

All but the above are ture, including "0" (zero in quotes), "false" (false in quotes) , empty functions, [] (empty array), and {} ( Empty objects), are all true

var a =!! (0);    Falsevar B =!! ("0");  True

A comparison between types that are false:

false0 (zero), and "" (empty string) These three are all equal to "= ="

var c = (false = = 0); Truevar D = (false = = ""); True  var e = (0 = = ""); True  

NULL and the undefined is equal to, except for themselves, "= =" compared to other values.

var F = (Null = = False); False  var g = (Null = = NULL);//True  var h = (undefined = = undefined);//Truevar i = (undefined = = null);// True  

There's a special Nan, and he's not equal to any of the values.

var j = (NaN = = null); False  var  k = (Nan = = nan); //False

typeof (NaN) returns the "number", generally we use IsNaN () to determine whether a value is NaN

Above, if the use of "= = =" Strictly congruent and "!==" strict unequal, the situation is not quite the same, the two comparisons are included in the type and value

var L = (false = = 0); Truevar m = (false = = = 0); False

Two applicable methods are attached:

1. Check if an empty array is bit

var n =  ([].length = = 0)  //Ture

2. Check if a bit empty object

var obj = {};for (var i in obj) {    if (Obj[i]) {        return true;    } else {        return false;}    }
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.