Undefined
indicates that the variable has been declared but has not been initialized. It should be noted that when the TypeOf operator is used to determine the data type, the values returned by the undeclared and uninitialized variables are undefined
var message;
Console.log (typeof message),//undefined
Console.log (typeof age);//undefined
Null: Represents an empty object pointer
the value returned using the typeof operator is ' object ', and it should be noted that the undefined value is derived from a null value, so ECMA-262 the equality test for them to return true.
Console.log (null = = undefined);//true
The difference between undefined and null
(1) undefined means that a variable is not declared or declared but not assigned
(2) NULL is a value that represents "No value"
(3) JavaScript sets the unassigned variable default value to undefined
(4) JavaScript never sets a variable to null. It is used to show the programmer that a variable declared with VAR has no value.
(5) Undefined is not a valid JSON, and NULL is
(6) The type of undefined (typeof) is the type of Undefined,null (typeof) is object.
PS: They are all basic types
They are all Falsy (Boolean (undefined)//False, Boolean (NULL)/False)
You can judge whether a variable is undefined
typeof variable = = "undefined"
You can tell whether a variable is null or not
They are equal when they are compared, but they are not equal when compared with the three equals
NULL = = undefined//true
NULL = = undefined//False