JS basic data types and typeof

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.