JavaScript for Beginners

JavaScript Booleans

Booleans can only have two values: true or false.

 

Example :

 

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Booleans</h2>

<p>Booleans can have two values: true or false:</p>

<p id=”demo”></p>

<script>
let x = 5;
let y = 5;
let z = 6;

document.getElementById(“demo”).innerHTML =
(x == y) + “<br>” + (x == z);
</script>

</body>
</html>

 

Output

JavaScript Booleans

Booleans can have two values: true or false:

true
false

 

Description :

In JavaScript, a Boolean is a data type that can have only two possible values:

True or False

  • False values include: false, 0, "" (empty string), null, undefined
  • All other values are considered true

Booleans are often used to control the flow of programs through conditions and logic checks, such as if statements, loops, and logical operations. Normally JavaScript booleans are primitive values created from literals