As long as it is about JS variables and data types, you can not open null and undefined, the two brothers is the important basis of JS, it is necessary to observe, countless students have used a magnifying glass multi-angle multi-batch study of the brothers, is very popular. ^-^
JS is really weird, there is a null enough, but also to toss out a undefined.
Although it is criticized, but this is the design.
In C # and Java, null means NULL, and no memory is allocated.
Null in JS takes number (NULL) as the result of 0, which means that it is not empty, is simply null, there is no value, and its data type is "Object".
So to represent the empty, so the designer made a undefined, it has a separate data type is "undefined".
The result of using number (undefined) is Nan, and the result of the conversion can be achieved for design purposes.
As a result of this design, the conversion of data types in an expression plays a key role.
An undefined variable or a defined but unassigned variable represents an empty, or undefined, value.
Undefined more is the use of JavaScript itself.
For example, the code farm to delete an object's properties is not to assign this property to undefined, because this property is still in, with hasOwnProperty to detect this property or exist, where some logic needs to be judged by the problem, if you delete the attribute is the predecessor delete.
var o1={p1: ' v1 ', P2: ' v2 '};o1.p2=undefined;o1.hasownproperty (//true
To delete an array element, for no side effects, use splice.
If you use undefined to assign values, you need to think clearly.
For code farmers, more is the use of NULL, you can assign a variable above the value, break the contact with the object instance, to ensure garbage collection, or in case the variable symbol for subsequent use.
Null and undefined are also pit pits when compared.
NULL // true NULL false // false false // false
Although weird, but that's the result, that's the design.
You can view the relevant definitions for ECMA-262, the rule Definitions Link 1, link 2.
END
Talk about JavaScript null and undefined