Text of the public number
There are 5 basic types of javascript: boolean,number,null,undefined,string; and a complex type: object;
Undefined: There is only one value, and the special undefined. When declaring a variable with VAR but not initializing it, the value of the variable is undefined, in short, undefined is the value that represents the variable declared but not initialized.
Note: Values that have not been declared directly alert their value to an error instead of displaying undefined; but if a variable that declares an unassigned is the same as the typeof result shown by an undeclared variable--->undefined
code example:
<script type= "Text/javascript" >var Str;alert (typeof str); // undefined alert (typeof message); // undefined</script>
Undefined must be nan when participating in numerical operation, and the undefined is displayed directly when the concatenation of strings is added.
code example:
<script type= "Text/javascript" >var B;alert (b+3); // Output NAN Alert (b+ ' 3 '); // Output UNDEFINED3</script>
Null: The object is ready to be saved, and the value of the object is not actually saved. From a logical point of view, a null value represents an empty object pointer. This means that null is relative to the object, so typeof (NULL) is an object.
Null is automatically converted to 0 when participating in a numeric calculation, and string concatenation is displayed as a string "null"
code example:
<script type= "Text/javascript" >var A=null;alert (null+3+5);//8alert (null+ ' hellow ');//nullhellowalert (null+3 + ' Hellow ');//3hellowalert (null+ ' hellow ' +3);//nullhellow3</script>
Contact: alert (null=undefined);//true ECMAScript that undefined is derived from null, they are defined as equal.
How to differentiate?
Alert (typeofnulltypeof undefined); alert (null = = = undefined);
Null and Undefind differences in JavaScript