Javascript Reference - JavaScript Boolean toString() Method








The toString() method returns a boolean value as a string.

Browser Support

toString() Yes Yes Yes Yes Yes

Syntax

boolean.toString()

Parameters

None.

Return Value

A String, either true or false;





Example

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: