About JS data types
There are five kinds of simple types: undifined, Null, Boolean, number, String
Complex types have one: Object
Using the typeof operator to get the data type, this operator returns a string
undifined
Boolean
String
Number
Object
function
Type undifined
There is only one value, which is undifined
typeof uninitialized variable, returns undifined
typeof a variable that is not declared, returns undifined
Null type
There is only one value, which is null
typeof Null returns an object
Boolean type
Only two literals: true, False
All types of values have values that are equivalent to these two values
Number Type
Represents a floating-point number with a maximum precision of 17 decimal places, but less precision than an integer
var a = 0.1;
var B = 0.2;
Then: A + b = 0.30000000000000004
Therefore, the use of floating-point numbers need to pay attention to accuracy. You can do this using the following methods:
functionAccadd (arg1, arg2) {varR1, R2, M, C; Try{r1 = arg1.tostring (). Split (".") [1].length}Catch(e) {r1 = 0 } Try{r2 = arg2.tostring (). Split (".") [1].length}Catch(e) {r2 = 0} C= Math.Abs (R1-R2); M= Math.pow (10, Math.max (R1, r2))if(C > 0) { varCM = Math.pow (10, c); if(R1 >R2) {Arg1= Number (arg1.tostring (). Replace (".", "")); Arg2= Number (arg2.tostring (). Replace (".", "")) *cm; } Else{arg1= Number (arg1.tostring (). Replace (".", "")) *cm; Arg2= Number (arg2.tostring (). Replace (".", "")); } } Else{arg1= Number (arg1.tostring (). Replace (".", "")); Arg2= Number (arg2.tostring (). Replace (".", "")); } return(Arg1 + arg2)/m}
View Code
Range of values:
Number.min_value
Number.MAX_VALUE
Values beyond the range are: Infinity, which can be judged by the isfinite () function.
NaN represents a non-numeric value, which is itself a numeric object
The biggest feature is not equal to any value, even if the Nan,isnan () function can determine whether it is Nan
numeric conversions
Conversion rules for number () functions
parseint ()
Determines whether a numeric pattern is met, ignores the opening space until the first non-null character is encountered, and resolves to the first non-numeric value
parseint (parameter 1,16) means using a 16-binary conversion with the meaning of the parameter as a binary
Parsefloat ()
Use the same method as above
String type
Object type
objects can be created by using new. The object type in JS is the basis for all of its instances. Methods and properties in object are present in more specific objects
Constructor constructor to save the function that creates the current object
hasOwnProperty (PropertyName) checks whether a given property exists in the current object
isPrototypeOf (object) checks whether an incoming object is a prototype of the current object
propertyIsEnumerable (PropertyName) checks whether a given property can use the For-in statement to enumerate
toLocaleString () returns the string representation of an object
ToString () returns the string representation of an object
ValueOf () returns the string, numeric, or Boolean representation of the object. Usually the same as the return value of the ToString () method
JavaScript Series notes (i) Data types