In the various data types defined in the programming language, we will define a null value or a false value for it, such as a null value for the object type null,.net the null value of the database field in the framework Dbnull,boolean false value of the type, 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, in addition to the Boolean value itself is true and false in the two cases, the other data types of "null" is mainly undefined and defined the two major categories. The types of these null values are:
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, that is, we are not able to perform null.tostring (), The default invocation of an object instance such as Null.constructor. 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 () are valid executable expressions.
In fact, these 5 values in the above mentioned in these differences, not too will give process control too big 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:
This conversion relationship requires special attention when doing string accumulation, no, this will cause some unexpected problems, and today we are going to get confused by the default to NULL.
Summary of differences between undefined, null, "", 0 value, and false in JavaScript