True, False, and Comparisons

Yes/no values and asking questions

8 min read · runnable Javascript

Sometimes the answer to a question is simply yes or no. In JavaScript we have a special kind of value for this called a boolean (named after a mathematician called George Boole). A boolean is either true or false, with no quotes.

let isRaining = true;
let isSunny = false;

Comparing values

You often create booleans by comparing two values. The result of a comparison is always true or false. Here are the comparison operators:

  • > greater than
  • < less than
  • >= greater than or equal to
  • <= less than or equal to
  • === exactly equal to
  • !== not equal to
console.log(5 > 3);    // true
console.log(5 < 3);    // false
console.log(4 === 4);  // true
console.log(4 !== 5);  // true
Tip: To check if two things are equal, use three equals signs ===. Remember: one = stores a value, three === ask a question. Mixing these up is one of the most common beginner slip-ups.

Try it yourself

Run the comparisons below and try some of your own.

Try it yourself
Output
Press “Run code” to see the result.

Quick check

Q1 What are the only two possible boolean values?

Q2 Which operator checks if two values are exactly equal?

Want to save your progress? It's free.

Create a free account