What is a Boolean Data Type?
A Boolean data type represents a logical value that can be either true or false. It is named after George Boole, an English mathematician and logician who first defined the concept of Boolean algebra in the mid-19th century.
var isActive = true; var isAuthenticated = false;
- Negation Operator (!): This operator reverses the value of a Boolean expression. For instance, if a variable has a value of true, applying the negation operator will make it false, and vice versa.
- Logical AND Operator (&&): This operator returns true if both operands are true; otherwise, it returns false.
- Logical OR Operator (||): This operator returns true if at least one of the operands is true; otherwise, it returns false.
- Boolean(): This function converts a value into its corresponding Boolean representation. If the value is considered “truthy”, such as a non-empty string or a number different from zero, the function will return true.
Otherwise, it will return false.
- typeof: The typeof operator returns the data type of a given value. When used with Boolean values, it returns “boolean”.