Home >Web Front-end >JS Tutorial >Example parsing the toString() method and valueOf() method of JS Boolean object_Basic knowledge
toString() method
Convert Boolean value to string and return the result.
Example
Convert boolean to string:
var bool = new Boolean(1); var myvar = bool.toString();
Output result:
true
Definition and usage
The toString() method converts a logical value to a string and returns the result.
Note: JavaScript will automatically call this method when you need to convert a Boolean object into a string.
Grammar
boolean.toString()
Return value
"true" or "false"
var bool = new Boolean(0); var myvar = bool.valueOf();
Output result:
false
Grammar
boolean.valueOf()
Return value
"true" or "false"