JavaScript data types are very concise, it only defines the basic data types in 6
•null: empty, none. It means that it does not exist. When the object's attribute is assigned to null, it means that the attribute is deleted.
•undefined: Undefined. This value is displayed when a variable is declared but no assignment is made. Can assign values to undefined
•number: numeric value. The most primitive data type, the carrier for expression calculation
•string: string. The most abstract data type, the carrier of information dissemination
•boolean: Boolean. The most mechanical data type, the carrier of logical operations
•object: object. Object-oriented basics
#When a variable pops up: var aa;alert(aa); //Variable definition, undefined undefined, undefined variable is also undefined#When judging whether a variable exists: var str;if( str == undefined ) //Variable definition, you can judge if ( str == undefined ) //Variable not defined, error ReferenceError: str is not defined So, when judging whether a variable does not exist, use if( typeof str == undefined )
typeof:
alert(typeof 1); // Return the string "number" alert(typeof "1"); // Return the string "string" alert(typeof true); // Return the string "boolean" alert(typeof {}); // Return the string "object" alert(typeof []); // Return the string "object " alert(typeof function(){}); // Return the string "function" alert(typeof null); // Return the string "object" alert(typeof undefined); // Return the string "undefined"You will find that: The JavaScript interpreter believes that null is a special form of object data type, and function(){} is a function type, which means that functions are also a basic data type, not a special form of objects.
In fact, in JavaScript, a function is a data type that is extremely easy to cause misunderstanding or ambiguity. It can be an independent function type, it can be used as an object method, it can be called a class or a constructor, it can also exist as a function object, etc.
Therefore, in the "Authoritative Guide to JavaScript", function is regarded as a special object of the object's basic data type. In addition, "Understanding JavaScript" and "Advanced JavaScript" also regard functions as objects, rather than as basic data type. However, in "The Essence of JavaScript Language and Programming Practice", function is regarded as a basic data type, while null is regarded as a special form of object type. As for who is right and who is wrong, it seems that it only depends on the specific situation.
The above article briefly discusses the basic data types and typeof of js are all the content I have shared with you. I hope you can give you a reference and I hope you can support Wulin.com more.