How to declare a boolean in JavaScript?

In JavaScript, you can declare boolean values using the "boolean" data type, which can have only two possible values: true or false. Here are some examples:

// Declaration of boolean values
let isTrue = true;
let isFalse = false;

// Boolean operations
let result1 = isTrue && isFalse; // logical AND
let result2 = isTrue || isFalse; // logical OR
let result3 = !isTrue; // logical NOT

console.log(result1); // Output: false
console.log(result2); // Output: true
console.log(result3); // Output: false

In the example above, we declare two boolean values, "isTrue" and "isFalse", and then perform some logical operations using operators such as "&&" (logical AND), "||" (logical OR), and "!" (logical NOT). We then log the results of these operations to the console using the "console.log()" method.

Boolean values are often used in conditional statements, such as "if" statements, to control the flow of program execution based on whether a condition is true or false. For example:

let age = 18;

if (age >= 18) {
    console.log("You are an adult.");
} else {
    console.log("You are a minor.");
}

In this example, we use the "if" statement to check if the "age" variable is greater than or equal to 18. If it is, we log the message "You are an adult." to the console. Otherwise, we log the message "You are a minor." to the console.