The valueOf()
method returns the primitive value of a boolean.
valueOf() |
Yes | Yes | Yes | Yes | Yes |
boolean.valueOf()
None
A Boolean, either 'true' or 'false'
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: