Sikau

JavaScript · Day 10 · about 25 min

True or false

Booleans and comparing values.

Yes or no questions

Is the shop open? Is the password long enough? Is this person over 18? Programs constantly ask yes/no questions. Today you'll learn how JavaScript answers them.

true and false

JavaScript has a special kind of value with only two options: true and false. It's called a boolean.

const isOpen = true;
const isRaining = false;
console.log(isOpen, isRaining);

Boolean variable names often start with is, has or can: isOpen, hasTicket, canVote. They read like a question.

The rest of this lesson

  • Comparing valuesexplain
  • Storing the answerexplain
  • Comparing text, and == vs ===explain
  • Predict the outputpredict
  • Read the operatormatch
  • Your turnwrite code
  • Password checkwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 68 lessons of JavaScript