Chapter 11
JavaScript Booleans
A Boolean value represents one of two states: true or false.
01 • Learn
What is JavaScript Booleans?
- Booleans are commonly used for yes/no decisions and application states.
- true represents one logical state and false represents the other.
- Boolean values are important in conditions and decision-making.
- Comparisons and logical expressions commonly produce Boolean results.
02 • Syntax
Syntax
let isLoggedIn = true; let isAdmin = false;
03 • Example
Example
Try understanding this code before running it.
let isLoggedIn = true;
if (isLoggedIn) {
console.log('Welcome back!');
} else {
console.log('Please login.');
}
04 • Remember
Important Points
- Boolean values should not be placed inside quotes when you need an actual Boolean.
- true and false are written in lowercase.
- Comparison and logical expressions return Boolean values.
05 • Avoid
Common Mistakes
- Writing 'true' when an actual Boolean true is required.
- Using incorrect capitalization such as True or FALSE.
- Confusing Boolean values with numbers.
06 • Practical
Real-World Use
Login status, account status, payment status, permissions, feature switches, and form validation often use Booleans.
07 • Practice
Practice Exercise
Practice: Boolean
Create an isStudent Boolean variable. If it is true, print 'Student Account' in the console.
Ready to write code?
Open the JavaScript editor and run your code with live output.