Javascript Reference - JavaScript Boolean valueOf() Method








The valueOf() method returns the primitive value of a boolean.

Browser Support

valueOf() Yes Yes Yes Yes Yes

Syntax

boolean.valueOf()

Parameters

None

Return Value

A Boolean, either 'true' or 'false'

Example

The following code shows how to get the primitive value of a Boolean object.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<!--from w w  w  .j av  a 2s  .c  om-->
<p id="demo"></p>

<script>
function myFunction() {
    var bool = false;
    var x = bool.valueOf();
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: