Sikau

JavaScript · Day 14 · about 25 min

And, or, not

Combining rules.

Rules with two parts

"You can go trekking if you have a permit and good boots." "The shop is closed on Saturday or a holiday." Real rules combine conditions. JavaScript has three logical operators for that.

&& means and

a && b is true only when both sides are true.

const hasPermit = true;
const hasBoots = false;

console.log(hasPermit && hasBoots);

if (hasPermit && hasBoots) {
  console.log("Off to the mountains!");
} else {
  console.log("Not ready yet.");
}

The rest of this lesson

  • || means or, ! means notexplain
  • Building conditions step by stepexplain
  • Predict the outputpredict
  • Combine the rulespredict
  • Your turnwrite code
  • Challengechallenge
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 68 lessons of JavaScript