Boolean Data Type
Boolean data type programming ka ek logical data type hota hai jisme sirf do hi values hoti hain: true aur false. Iska use computer programs me decisions lene aur conditions ko check karne ke liye kiya jata hai.
1. Boolean Kya Hota Hai? (Very Simple Explanation)
Boolean ka matlab hota hai: “Kya ye baat sahi hai?” → true “Kya ye baat galat hai?” → false
- “Fan chal raha hai?” → true/false
- “User login hai?” → true/false
- “Internet connected hai?” → true/false
2. Boolean Ki Main Properties
- Boolean me sirf do hi values hoti hain.
- Logical operations ke liye use hota hai.
- Memory bahut kam use karta hai.
- Program ko decision dene me help karta hai.
3. Boolean Data Type Ki Memory Size
Language ke hisab se memory size alag hoti hai, lekin commonly:
| Language | Boolean Size | Values |
|---|---|---|
| C / C++ | 1 byte | true / false |
| Java | 1 bit internally | true / false |
4. Boolean vs Integer – Clear Comparison
| Feature | Boolean | Integer |
|---|---|---|
| Values | true / false | Numbers |
| Use Case | Decision making | Calculations |
| Speed | Faster | Normal |
| Memory | Very Low | More |
5. Boolean Values Ka Behavior (Advanced Concept)
Boolean conversion rules (important):
- 0 → false
- Non-zero number → true
- "" (empty string) → false
- "text" (non-empty string) → true
- null → false
- undefined → false
6. Boolean Logical Operators (AND, OR, NOT)
| Operator | Meaning | Example |
|---|---|---|
| AND (&&) | Dono true honge tabhi result true | true && false → false |
| OR (||) | Ek bhi true ho to result true | false || true → true |
| NOT (!) | Value ko ulta kar deta hai | !true → false |
7. Boolean Example Programs (JavaScript)
Basic Example
let isLogin = true;
let isAdult = false;
console.log(isLogin);
console.log(isAdult);
Boolean with condition
let age = 20;
let canVote = (age >= 18);
console.log(canVote); // true
Boolean in If-Else
let rain = false;
if (rain) {
console.log("Umbrella le lo");
} else {
console.log("Weather clear hai");
}
Boolean with AND/OR
let hasID = true;
let ageCheck = false;
if (hasID && ageCheck) {
console.log("Entry allowed");
} else {
console.log("Entry denied");
}
8. Boolean Advantages
- Bohot kam memory use karta hai.
- Conditions ko easy banata hai.
- Program execution fast hota hai.
- Code readable & clean rehta hai.
- Decision making ke liye best data type.
9. Boolean Disadvantages
- Sirf 2 values hone ki wajah se limited use hota hai.
- Numeric calculations ke liye kaam nahi aata.
- Type conversion errors ho sakte hain.
10. Boolean Use Cases (Real Applications)
- Login/Logout system
- Form validation
- Game logic (win, lose)
- Payment success check
- Access control
- Switch ON/OFF logic
11. Final Summary
Boolean data type programming ka sabse important logical type hai jo program ke decision aur flow ko control karta hai. True/False ke through program smart decisions leta hai. Isiliye Boolean ko programming ka decision maker bhi bola jata hai.
Comments
Post a Comment