In JS, for a variable without a given initial value after life, a value of undefined is given. But the premise is that the variable must have been declared, if it is not declared variables, will be an error.
v1; // error, VI is not defined var // undefined var v2 = ""; //
Typical Uses of undefined:
1. The variable is declared, but no assignment is undefined;
2. When calling a function, the parameters that should be provided are not provided, then the default parameter is undefined;
3. There are no assigned attributes in the object, which is undefined;
4. If the function does not return a value, undefined is returned by default.
In contrast, NULL represents a special value of object that is used to represent the concept of a null reference. If you want an identifier to be declared as object, but you do not give him an instance temporarily, you can first initialize it to null for later use.
Typical Uses of NULL:
1. Null means no object, that is, there should be no value here;
2. As a function parameter, indicates that the function's parameters are not objects;
3. As the focus of the object prototype chain.
A very interesting statement to:
null; // true null; // false
There is a very interesting statement on the Internet, of course, I also feel that this statement is very reasonable:
Undefined is derived from null: the base data type has a reference type corresponding to it. Just like number corresponds to number, Boolean corresponds to Boolean ... They have the same behavior, and each of them will have similar unpacking and boxing operations.
For the behavior of NULL and undefined:
1. Null participation in numeric operations is automatically converted to 0;
2. typeof Null returns an Object because null represents a reference with no value;
3. Undefined is a special property of the global object whose value is the undefined type's proprietary value undefined;
4. When undefined participates in any numerical operation, the result must be Nan;
Are the original notes on the finishing, some of the source has not been found, and so on later to see the source of time to make up, sorry ...
Undefined and null understanding