Data type of JS

Source: Internet
Author: User

First, preface:

  The variable in JavaScript seems simple because it declares that a variable requires only a "Var", unlike other programming languages that strictly differentiate the data type (Int/double/char/boolean ... )。 This is also beneficial, variables can be given any type of value, the same can be re-assigned to the variable value of different types. Not "for a lifetime."

  

However, JavaScript does not circumvent the data type, but only uses the untyped "var" keyword uniformly when declaring, and its data type is determined based on the type of the value being assigned.

varx = 1;//Number typevarx = 0.1;//number type, JS does not distinguish between integer value and floating point valuevarx = "Hello World";//string consisting of text in double quotation marksvarx = ' JavaScript ';//text within single quotation marks can also form a stringvarx =true;//True and False as Boolean valuesvarx =NULL;varx = undefined;//null and undefined are very similar and are special types

Second, the text:

The following is a description of the different data types

Data type classification Description Detailed classification

Original type
  • Original value cannot be changed
  • The comparison of the original values is also worth comparing

For example: var a = 1, b = 1;

A = = B; True

Numbers (number)
Strings (String)
Boolean Value (Boolean)
Null
Undefined
Object type
  • The object is mutable, that is, the value can be modified
  • Object comparisons are not worth comparing

For example: var a = [], b = [];

A = = B; False, only two will be equal if the reference is identical

Special objects--arrays (array)
Special objects-functions (function)
Object type

A few notes:

    • Undefined represents the vacancy of a system-level, unexpected, or similar error value, indicating a missing value, where there should be a value but not defined.  For example: Var A; A will show undefined

NULL indicates a vacancy at the program level, normal, or expected value;

Generally use null more often.

  • undefined null0-0NaN""  // empty string

    These values are converted to False in a Boolean conversion. But that's not enough to make you think they are equal to false:

  • undefined = =true   //falseundefined = =false  //falseundefined==NULL    //trueundefined = = =NULL  //falseNULL==false          //falseNULL==true            //false"" ==false              //true"" ==true               //false0 = =false               //true0 = =true                //false-0 = =false              //true-0 = =true               //falseNaN==false           //falseNaN = =true            //falseNan = = Nan//false Nan is not equal to any value, including itself

Data type of JS

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.