Skip to content
dreamcode
dreamcode
Map
Logical ops
Lesson 9 of 48
+15 XP on finish
JAVASCRIPT CLIMBSChapter 2 · JS Conditionals & Logic

Boolean Operators

Use && (AND) to require both sides to be true, || (OR) to succeed if either side is true, and ! (NOT) to invert a boolean value.

Worked example

How it reads

  • hasKey || hasPass evaluates to true because at least one is true
  • !hasKey flips true to false
Cloud tip: Logical operators short-circuit: if the result is determined by the first condition, the second condition is not evaluated.
index.js
JAVASCRIPT
real JavaScript, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Add const raining = true; and require !raining in the condition too, so the program logs No view.

Press Run to check your work.