The JavaScript data type is very concise, it only defines the basic data type in 6
- Null: null, none. Represents a non-existent when the property of an object is assigned a value of null, which means that the property is deleted
- Undefined: Not defined. This value is displayed when the declared variable is not assigned a value . You can assign a value of undefined to a variable
- Number: Numeric value. The most primitive data type, the vector of expression computation
- String: Strings. The most abstract data type, the carrier of information dissemination
- Boolean: Boolean value. The most mechanical data type, the carrier of the logical operation
- object: Objects. Object-Oriented Fundamentals
#当弹出一个变量时: var aa;alert (aa); // variable definition, popup undefined #当判断一个变量是否存在时: var str; if (str = = undefined) // variable definition, so you can judge if(str = = undefined) // variable undefined, error referenceerror:str is not defined if typeof str = = ' undefined ')
Use of typeof:
typeof can be used to detect the data type of a given variable and to return a string that represents the data type of the expression.
Alerttypeof1);//returns the string "number"Alerttypeof"1");//returns a string of "string"Alerttypeof true);//returns the string "Boolean"Alerttypeof{});//returns the string "Object"Alerttypeof[]);//returns the string "Object"Alerttypeof function(){});//returns the string "function"Alerttypeof NULL);//returns the string "Object"Alerttypeofundefined);//returns the string "undefined"
JS data type