JavaScript booleans can have one of two values: true or false.
We can use the Boolean()
function to find out if an expression is true.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!-- w w w. ja va2s . com-->
<script>
function myFunction() {
document.getElementById("demo").innerHTML = Boolean(10 > 9);
}
</script>
</body>
</html>
The code above is rendered as follows:
Property | Description |
---|---|
prototype | Add properties and methods to the Boolean prototype |
Method | Description |
---|---|
toString() | Converts a boolean value to a string |
valueOf() | Returns the primitive value of a boolean |