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