(1) Converted to string
Copy code code as follows:
X + ''
Tostring ()
String ()
The function converting to a string generally outputs the function body, but it can rewrite its Tostring method
(2) Convert to numbers
Copy code code as follows:
Parseint (), PARSEFLOAT ()
Use number (), do not add NEW before, so it is converted into an object.
Participate in mathematical operations (except the way to add method)
+ X: Note that this is not a way to add
(3) Converted to Boolean
Automatic conversion: IF statement, ||, && ,! and other logical judgment environments will automatically convert the expression to Boolean value
Mandatory conversion: Use !!, use Boolean (), don't add New before, so that it is converted into an object.
(4) Converted to object
Direct NEW+object name
(5) Summary
All types are: object names (variables to be converted) conversion methods, and some techniques that are independent.
The type conversion of JS can refer to the figure below: