Boolean toString() Method - Javascript Boolean

Javascript examples for Boolean:toString

Description

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

This method is called whenever a boolean is used in a string operation.

Parameters

None.

Return Value:

A String, either "true" or "false"

The following code shows how to Convert a Boolean value to a string:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from  ww w  .j av a  2  s . c  om*/
    var bool = true;
    var x = bool.toString()
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials