First, convert to numeric type
1.number ( parameter ) converts any type to a numeric type
A. if it is a Boolean value,false is 0andtrue is 1
B. if it is a number, the conversion becomes itself. Remove the meaningless back guide 0 .
C. if Null is converted to 0
D. if undefined is converted to NaN not a number
E. if the object calls the object's valueOf () First, if valueOf () returns NaN, then the object is called the toString ()
F. if it is a string
1. If there is only a number in the string, convert to ten ( ignoring leading 0 and 0)
2. if it is a valid canonical floating-point type, convert to a floating-point value ( ignoring leading 0 and trailing 0)
3. if it is an empty string, convert to 0
4. if it is a different value, return NaN
2,parseint ( parameter 1, parameter 2) converts a string to an integer
A. if a string contains only numbers, it is converted to an integer in the form of a binary.
B. he automatically ignores the spaces in front of the string, knowing that the first non-null numeric string is found until the end of the string that resolves to the first non-numeric value.
C.returns NaN If the first character of the string is not a space, number, or-
D. parameter 1 = > string
parameter 2 = > binary
3.parsefloat () converts a string to a floating-point number
A. among the strings . only the first one is valid and the others are invalid.
B. If the string is a valid integer, he returns an integer and does not return a floating-point number.
Second, convert to string type
1.String ( parameters ) can convert any type to a string
Null and undefined: will also be converted to strings, respectively, null and undefined
Boolean type : returns true and false
Numeric type : string of itself
2.toString ()
The calling Format Object . toString ()
The function is to represent the object as a string
Array.tostring () , separated by a string
Boolean.tostring () two value true false
String.tostring () returns itself
Number.tostring ( argument ) returns the string form itself
"Numeric types can use parameters (2-32) to control the output mode "
NOTE:null and undefined do not have the toString () method
Third, convert to Boolean type
Boolean () to convert any type of value to a Boolean value
Convert to False : "", 0, NaN ,undefined, False
All the others are converted to true.
This article is from the "Programmer Technology Exchange" blog, please be sure to keep this source http://bjishu.blog.51cto.com/7481301/1670348
JavaScript Data type Casting