Q1. What is Boolean in JavaScript?
Boolean is a data type that represents logical values. It can have only two possible values:
Booleans are mainly used in conditions, comparisons, and decision-making.
Example
- true
- false
Example
let isLoggedIn = true;let isAdmin = false;Q2. Where Are Boolean Values Commonly Used?
Boolean values are commonly used in:
Example
- Conditional statements
- Comparison operations
- Loops
- Logical operations
- Form validations
let age = 18;
if(age >= 18) { console.log(true);}Q3. How Are Boolean Values Created in JavaScript?
Boolean values can be created in two ways:
1. Direct Assignment
2. Using Comparison
Output
1. Direct Assignment
let status = true;2. Using Comparison
let result = 10 > 5;console.log(result);Output
trueQ4. What is Boolean Conversion in JavaScript?
JavaScript automatically converts values into Boolean when used in conditions. This process is called Boolean conversion.
Example
Example
Boolean(1); // trueBoolean(0); // falseBoolean(""); // falseBoolean("Hello"); // true