The JavaScript data type is very concise, it only defines 6 basic data types
- 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 undefinedalert (AA); Variable not defined, undefined, undefined variable is also undefined#当判断一个变量是否存在时:var str; if (str==undeifined)//variable definition, this can be judged if (str==undeifined)//variable undefined, error referenceerror:str is not definedSo, when judging if a variable does not exist, use if (typeof str = = undefined)Typeof:alert (typeof 1);//Returns the string "number"alert (typeof "1"); Returns a string of "string"alert (typeoftrue); //Returns the string "Boolean" alert (typeof {}); //Returns the string "Object" alert (typeof []); //Returns the string "Object" Alert (typeof function () {}); //Returns the string "function" alert (typeof null); //Returns the string "Object" alert (typeof undefined); //Returns the string "undefined" You will find that the JavaScript interpreter considers NULL to be a special form of the object data type, and function () {} is a function type, meaning that in JavaScript, A function is a data type that is highly misleading or ambiguous, can be a separate function type, can be used as a method of an object, can also be called a class or constructor, and can exist as a function object. So, in the JavaScript authoritative guide, function is treated as a special object of the object's basic data type, and "Enlightened JavaScript" and "JavaScript advanced Programming" also treat functions as objects, rather than as a basic data type. However, in the language of JavaScript and programming practice, function is regarded as a basic data type, and Null is regarded as a special form of object type. As to who is right and who is wrong, it seems only according to the specific circumstances.
JS basic data types and typeof