JavaScript has two data type conversion methods:
(1) Convert the entire value from one type to another data type (called basic data type conversion)
(2) Extract a value of another type from one value and complete the conversion work
Three methods of basic data type conversion:
1. Convert to character type: String(); Example: The result of String(678) is "678"
2. Convert to numeric type: Number(); Example: The result of Number("678") is 678
3. Convert to Boolean Type: Boolean(); Example: The result of Boolean("aaa") is true
Method to extract another type of value from one value:
1. Extract the integer from the string: parseInt(); Example: the result of parseInt("123zhang") is 123
2. Extract the floating point number from the string: parseFloat(); Example: parseFloat("0.55zhang" ) is 0.55
3. Execute a piece of javascript code represented by a string: eval(); Example: the result of zhang=eval("1 1") is zhang=2
Note: Number, The String function is a special function. In the JS engine, it will automatically determine whether to call it as a constructor or a normal call, so you can use the new keyword or call it directly as a function.