In the previous article, we talked about how to turn a numeric type, and today summarizes the methods for turning strings and Boolean types:
The main methods of the string transfer are:
ToString ();
String ();
The specific usage is shown in the following table:
Method |
Example |
return value |
Description |
ToString (): Undefined and null do not have the ToString () method |
[' 1 ', ' 2 ', ' 3 '].tostring () |
The |
Converts the element of an Array to a string. The resulting strings are separated by commas and joined together. |
True.tostring () |
"True" |
Returns "true" if the Boolean value is true. Otherwise, return "false". |
var num = 111; Console.log (Num.tostring ()); |
"111" |
Numeric type to String type |
String () |
string () converts null and undefined to a string, but cannot be converted to a string. String (NULL), which returns "null". String (undefined), which returns "undefined". |
The main types of turn Boolean methods are:
Boolean ():
The specific usage is shown in the following table:
Method |
Example |
return value |
Description |
Boolean (): Convert any type of value to a Boolean value |
Boolean (False) |
False |
False, "", 0, NaN, null, undefined, and any other value will be converted to true. |
Boolean ("") |
False |
Boolean (0) |
False |
Boolean (NaN) |
False |
Boolean (undefined) |
False |
Boolean ("false") |
True |
The string type "false" turns to a Boolean type of false: var value = "false"; var flag = value = = = "False"? False:true; |
Conversion of JS type to string and Boolean type