Null and undefined in js
Null is a keyword in js, indicating a null value. Null can be considered as a special value of the object type. If the value of an object is null, it indicates that this object is not a valid object. Here, null and 0 are not the same thing. In c ++, null is usually defined as 0, but not in js.
Undefined is not a js keyword. It is a Global variable, that is, an attribute of Global. In the following three cases, undefined is returned:
1. An undefined variable is used;
2. variables defined but not assigned values are used;
3. An object property is used, but the property does not exist or is assigned a value;
Although undefined and null are different, running the following code returns true.
Alert (undefined = null );
Var v = ""; alert (v. a = null); alert (v. a = undefined );
This is because undefined and null indicate the value is missing, so here they are equivalent. But not completely equal. The following code returns false.
Alert (nudefined = null );