This article mainly introduces the toString () method and valueOf () method of the Boolean object in JS. it is the basic knowledge in JavaScript beginners. For more information, see
ToString () method
Converts a Boolean value to a string and returns the result.
Instance
Convert a Boolean value to a 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 to a string.
Syntax
boolean.toString()
Return value
"True" or "false"
ValueOf () method
Returns the original value of a Boolean object.
Instance
var bool = new Boolean(0);var myvar = bool.valueOf();
Output result:
false
Syntax
boolean.valueOf()
Return value
"True" or "false"