typeof detects the data type of a given variable and distinguishes functions and other objects by TypeOfvar message = ' Some string '; Console.log (typeof (Message)); "String" Console.log (typeof (null)); "Object" is a special return value because NULL is considered an empty object reference. Attention:
- A variable that has not yet been declared can only do one thing, which is to use TypeOf to detect its data type
Undefined It is just a value, the value is Undefined.
scenario: When declaring a variable with VAR, but without an assignment (without initialization), the variable returns undefined.
The main purpose of undefined is to make a formal distinction between null object pointers and uninitialized variables, which I understand to distinguish whether the return value of a variable is null or undefinedWhen declaring a variable is not assigned a value, this variable is equivalent to undefined var message;console.log (message = = undefined); True no matter what the circumstances, do not put a variable value, set to undefined note:
- For unassigned variables and undeclared variables, when the typeof is executed, the undefined is returned;
- In the actual operation, only need to know a bit, when using typeof detection variables, if the return undefined, we will know that the variable is not assigned, or is not initialized;
NULL It has only one value, is the second data type with only one value, and its value is null.
it represents an empty object pointer that returns "object" when detected using TypeOf.var message = Null;console.log (typeof (Message)); "Object" If you define a variable that will be used to hold the object in the future, it is better to initialize the variable to NULL because NULL is an empty object. If the variable does not have a true save object, the value of this variable should be null, not the other data type
JavaScript Red Book Notes