Programming Basics
Boolean Logic (and/or/not)
The idea, in plain English
A boolean is just a yes/no, true/false light switch. Boolean LOGIC is how you combine switches. AND needs BOTH switches on to be true. OR needs AT LEAST ONE switch on. NOT just flips a switch to its opposite.
How it works
- 1`and` (written `&&` in JavaScript) is true only when both sides are true — like needing both a ticket AND being old enough.
- 2`or` (written `||` in JavaScript) is true when at least one side is true — like being let in for being a member OR being a kid.
- 3`not` (written `!` in JavaScript) flips a true into false, or a false into true.
When you'd use it
Use boolean logic any time a decision depends on combining more than one yes/no condition. Examples: checking permissions, validating a form, or deciding whether a game character can move.
Common beginner mistakes
- Mixing up `and` and `or`. 'And' is stricter — it needs everything true. 'Or' is looser — it needs just one true.
- Printing a raw `true`/`false` value straight into a sentence. It usually reads better to turn it into a word like 'yes' or 'no' first.
Try it — edit and run
Click the code to edit · press ⌘/Ctrl+↵ to run
Editable code. Tab and Shift+Tab indent. Press Escape, then Tab, to move focus out of the editor.
Expected output — hit Run to try it
Can watch (14, has ticket): yes
Can watch (10, has ticket): no
Can enter free (member, not kid): yes
Need umbrella: yesNot sure this is the right topic? See the learning paths → or where this leads →