The toString()
method returns a boolean value as a string.
toString() |
Yes | Yes | Yes | Yes | Yes |
boolean.toString()
None.
A String, either true or false;
The following code shows how to convert a Boolean value to a string.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<!-- w w w . j a va 2 s .c o m-->
<p id="demo"></p>
<script>
function myFunction() {
var bool = true;
var x = bool.toString()
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: