← Back to Course

➕ Operators, Comparisons, and Boolean Logic

Operators let you calculate values and compare them. Boolean logic lets you combine conditions so programs can make decisions.

Arithmetic and Comparison Operators

Example: Math and Comparisons

const total = 12 + 8;
const difference = 20 - 5;
const doubled = 4 * 2;
const half = 10 / 2;

console.log(total > difference);
console.log(doubled === half);
console.log(total !== 25);

Boolean Logic

Use && when both conditions must be true, use || when either condition can be true, and use ! to reverse a boolean value.

Example: Combining Conditions

const isLoggedIn = true;
const hasPaid = false;

console.log(isLoggedIn && hasPaid);
console.log(isLoggedIn || hasPaid);
console.log(!hasPaid);

🎯 Key Ideas

  • Use operators to transform and compare values
  • Every condition eventually becomes true or false
  • Boolean logic is the foundation for conditionals and loops
← Back to Code Foundations