Chapter 11

JavaScript Booleans

A Boolean value represents one of two states: true or false.

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.

Syntax

let isLoggedIn = true;
let isAdmin = false;

Example

Try understanding this code before running it.
let isLoggedIn = true;

if (isLoggedIn) {
    console.log('Welcome back!');
} else {
    console.log('Please login.');
}

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.

Common Mistakes

  • Writing 'true' when an actual Boolean true is required.
  • Using incorrect capitalization such as True or FALSE.
  • Confusing Boolean values with numbers.

Real-World Use

Login status, account status, payment status, permissions, feature switches, and form validation often use Booleans.

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.

Try It Yourself →