The undefined type has only one value, which is undefined. When the declared variable is not initialized, the default value of the variable is undefined.
The null type also has only one value, which is null. Null is used to represent an empty object pointer. Null is associated with an object reference, which represents an object reference that is either empty or nonexistent.
var A;
Alert (Null = = a); True
Alert (Null = = undefined); True
ECMAScript that undefined are derived from null, so they are defined as equal. However, if in some cases we must differentiate between these two values, you can use the following two methods.
Alert (Null = = = undefined); False
alert (typeof null = = typeof undefined); False
The type of undefined;null that is undefined with the TypeOf method is a different type of object,null and undefined, so the output is "false". and = = = Absolute equals, where null = = = undefined output false.
There are several cases where the value of the variable is undefined
1, variable definition, but not assigned value, the value of the variable is undefined
2, the calling method does not return a value, the value returned is undefined
3, the property value of the object does not exist, the return value is undefined, such as: DOCUMENT.D
When NULL participates in numeric operations, its value is automatically converted to 0, so the following expressions are evaluated to get the correct values:
Expression: 123 + null result value: 123
Expression: 123 * Null result value: 0
When undefined participates in any numerical calculation, the result must be Nan.
null and undefined in JS