1. JavaScript data types
There are 6 data types in JavaScript
Boolean String number Undefined Null
Object
The object type contains an array (arrays) function (functions) and other general pairs.
The number (Numbers) type can be an integer (intergers) or float point type and a special value of Nan and Infinity
The string (Strings) type contains an empty string "".
The Boolean value (Booleans) type has only two values of true and false.
The last two basic data types are a little special. The null type has only one value null undefined only one value undefined.
2. Detecting the data type of a given variable--typeof operator
Using typeof for a variable or value may return a string
1. "Undefined" If this value is undefined.
2. "Boolean"--if this value is a Boolean value
3. "String"--if this value is a string
4. "Number"--if the value is numeric
5. "Object"--if this value is an object or null
6. "Function"--if this value is a function
3.undefined type
1. Undefined has only one value, which is the special undefined.
2. When the declared variable is not initialized, the default value of the variable is undefined.
3. Executing the typeof operator on an uninitialized variable returns the undefined value, and the TypeOf operator that executes the undeclared variable also returns the undefined value.
4. If you use an operator other than typeof for an undeclared variable, it will cause an error, because the other operators can only be used on declared variables.
4. Boolean type
1. Boolean has two literal literals ture and false.
2. true and false case-sensitive true and false are not Boolean values but identifiers.
3. Various data types can be converted to their corresponding Boolean values by calling Boolean ()
5. Number Type
NaN (non-numeric not a number) generally occurs when a type (String Boolean) conversion fails.
Nan cannot be used in arithmetic calculations any operations involving Nan will return Nan
nan is not equal to any value including itself
You can use the isNaN () function to determine whether a parameter is "not a numeric value"
6. Numeric Conversions number parseint parsefloat
Number can be used with any data type
1. If it is a numeric value, simply incoming and outgoing;
2. If it is a Boolean value, True and False return 0 and 1 respectively;
3. If NULL, returns 0;
3. If it is undefined, return nan;
4. If it is a string: Only the numbers will be converted to decimal, the containing valid floating-point numbers will be converted to floating-point values, the containing valid hexadecimal format will be converted to decimal integers of the same size, the empty string will be converted to 0, and characters other than the above will be converted to Nan
5. If it is an object, call the object ValueOf () method and then convert the returned value according to the preceding rule, or call the ToString () method if the result of the conversion is Nan. The returned string is then converted according to the previous rule.
7. String type
① can be represented by "" or "
② includes some special character literals (escape sequences)
Once the ③ string is created, it cannot be changed, and if it is to be changed, the original string is destroyed and the variable is populated with a new string.
④ Convert a value to a string you can use the ToString () method by passing the cardinality output binary, decimal, hexadecimal, null, and undefined without the ToString () method.
The ⑤string () function can convert a value of any type to a string: if there is a ToString () method, call the method fan Hu The corresponding result, or null if the value is null, or return "undefined" if the value is undefined.
JavaScript learning the first JavaScript data type (2016/8/29 23:12)