There are 6 types of data in JS: Undefined, Null, Boolean, number, string, and object. Any mechanism for creating custom types is not supported in JS, and all values will eventually be the 6 data types. The dynamic nature of its data types is sufficient to represent all data. JS provides the typeof operator to detect the data type of a variable.
(typeof returns a string of six possible types: "Number", "string", "Boolean", "Object", "function", "undefined").
Let's take a look at undefined this data type, undefined type has only one special value--undefined. undefined means "missing value", that is, there should be a value here, but there is no definition. Typical uses are:
(1) The variable is declared, but when it is not assigned, it is equal to undefined.
(2) when calling a function, the argument that should be supplied is not provided, which equals undefined.
(3) The object does not have an assigned property, and the value of this property is undefined.
(4) When the function does not return a value, undefined is returned by default.
For example:
var color;
Alert (message = = undefined);//true
This example only declares the variable color, but does not initialize it. Comparing this variable with the undefined literal, the result shows that they are equal. This example is equivalent to the following example:
var color = undefined;
Alert (color = = undefined);//true
However, a variable that contains a undefined value is not the same as a variable that has not been defined:
var color;//The undefined value is obtained by default after a variable declaration
Non-declared variable
var age
alert (color); "Undefined"
alert (age); Error generated
However, executing the typeof operator on an uninitialized variable returns the undefined value, and the TypeOf operator that executes the undeclared variable also returns the undefined value.
Undefined value is obtained by default after var color;//variable declaration
Non-declared variable
var age
Alert (typeof color); "Undefined"
Alert (typeof age); "Undefined"
The results show that the typeof operator, which executes the uninitialized and undeclared variables, returns the undefined value, and the result is logically justified. Because although these two variables are fundamentally different from the technical point of view, it is virtually impossible to perform real operations on any of these variables.
Welcome to the public number: Wcs290130--javascript that thing.
JS in six data types (a)--undefined (turn)