JavaScript Boolean
Syntax
A boolean data type represents only two possible values: true
or false
. In JavaScript, the syntax for creating a boolean value is:
var myBoolean = true;
or
var myBoolean = false;
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Boolean Operations Example</title>
</head>
<body>
<!-- Placeholder for displaying the output -->
<p id="output"></p>
<script>
// Variables
var x = 5;
var y = 10;
// Boolean operations
var isGreater = x > y;
var isLessThan = x < y;
var isTrue = true;
var isFalse = false;
// Display results in the HTML document
document.getElementById("output").innerHTML += isGreater + "<br>";
document.getElementById("output").innerHTML += isLessThan + "<br>";
document.getElementById("output").innerHTML += isTrue + "<br>";
document.getElementById("output").innerHTML += isFalse;
</script>
</body>
</html>
Output
false
true
true
false