In a variety of data types, we will define a "null" or "false value" for it, such as a null value for the object type null, a null value for the database field in the. NET Framework DBNull, a Boolean type of false value False and so on. There are also many kinds of "null" and "false values" in JavaScript, so what do they have in common and different points?
In fact, in the title I have listed all the "null" and "False value" in JavaScript, except for the Boolean value itself is true and false , the other data type "NULL" Mainly undefined and defined are the two major categories. The types of these null values are:
typeof (undefined) = = ' undefined '
typeof (null) = = ' object '
typeof ("") = = = ' String '
typeof (0) = = ' Number '
typeof (false) = = ' Boolean '
The common denominator of these five values is that, in the IF statement, the false branch will be executed . Of course, in a broad sense, it means that these values are invalid or null values on their corresponding data types. And these five values! operation, the result is all:true.
There are also differences in these values, where undefined and null are special, although the type of null is object, but null does not have any attributes of the object, which means that we cannot execute Null. toString () The default invocation of an object instance. So in this sense,null and undefined have the greatest similarity. Look at the null = = undefined result (true) to be more descriptive. But similar to similar, there is a difference, that is, and the number operation, the result of the + null is: 10;10 + undefined result is: NaN.
In addition, "", 0, and false although the IF statement is represented as "false value", they are all meaningful data, but only as "null" or "False value" because: "". ToString (), (0). ToString () and False. ToString () is a valid executable expression.
in fact, these 5 values in the above-mentioned differences, is not very much to the process control caused too much problem, so what to distinguish them? It is important to note that the differences between these values are larger when converted to string, and their conversion relationships to string are:
String (undefined), "undefined"
String (NULL), "NULL"
String ("") , ""
String (0), "0"
String (False), "false"
This conversion relationship requires special attention when doing string accumulation, otherwise there will be some unexpected problems.
Undefined,null in JavaScript, "", 0 and false in the cloud