Logical operator ||

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Logical operator ||

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. If day is "Sat", what does day === "Sat" || day === "Sun" give?
A false
B true
2. Which result does true || false give?
A false
B true
3. When is a || b false?
A Only when both a and b are false
B When either a or b is false
4. Which line correctly checks if day is Sat or Sun?
A day === "Sat" || day === "Sun"
B day === "Sat" || "Sun"
5. If day is "Wed", what does day === "Sat" || day === "Sun" give?
A false
B true

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1day === "Sat" || day === "Sun" Ascore === 0 || score === 100
2false || false BGives false, because || is false only when both sides are false
3Either one of two conditions is enough to make the whole condition true Cconsole.log(5 > 10 || 2 > 8);
4|| gives false only when both conditions are false DOR is written with two vertical bars ||. A single | is a different operator.
5if (day === "Sat" || "Sun") { EThe right side of || is just the text "Sun", not a comparison. Each side of || needs its own full condition.
6if (day === "Sat" | day === "Sun") { FTrue when the day is Saturday or Sunday, so it is true on the weekend

Definitions

logical OR

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
let off = day === "Sat" __ day === "Sun";
2.
__ (day === "Sat" || day === "Sun") { console.log("Weekend!"); }
3.
let hasPass = false; let hasTicket = true; let canEnter = hasPass __ hasTicket;
4.
if (score < 0 || score _ 100) { console.log("Invalid"); }
5.
let isSat = day === "Sat"; let isSun = day === "Sun"; let off = isSat || _____;

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A let day = "Sun";
B let sat = day === "Sat";
C let sun = day === "Sun";
D console.log(sat | sun);
Question 2
A let temp = 38;
B if (temp < 0 || > 35) {
C console.log("Extreme");
D }
Question 3
A let age = 9;
B if (age < 5 or age > 65) {
C console.log("Free entry");
D }
Question 4
A let hasPen = false;
B let hasPencil = true;
C if hasPen || hasPencil {
D console.log("Can write");
E }
Question 5
A let isRaining = True;
B let isCold = false;
C if (isRaining || isCold) {
D console.log("Take a jacket");
E }

Answer Key

Logical operator ||
Section A: Quick Questions
Q1
B — true
Q2
B — true
Q3
A — Only when both a and b are false
Q4
A — day === "Sat" || day === "Sun"
Q5
A — false
Section B: Match the Pairs
Q1
day === "Sat" || day === "Sun" → True when the day is Saturday or Sunday, so it is true on the weekend
Q2
false || false → Gives false, because || is false only when both sides are false
Q3
Either one of two conditions is enough to make the whole condition true → score === 0 || score === 100
Q4
|| gives false only when both conditions are false → console.log(5 > 10 || 2 > 8);
Q5
if (day === "Sat" || "Sun") { → The right side of || is just the text "Sun", not a comparison. Each side of || needs its own full condition.
Q6
if (day === "Sat" | day === "Sun") { → OR is written with two vertical bars ||. A single | is a different operator.
Section C: Definitions
Q1
logical OR — Logical OR joins two conditions. It is true when at least one is true, and false only when both are false. Example: day === 'Sat' OR day === 'Sun' is true on a weekend.
Section D: Fill in the Blanks
Q1
let off = day === "Sat" || day === "Sun";
Q2
if (day === "Sat" || day === "Sun") { console.log("Weekend!"); }
Q3
let hasPass = false; let hasTicket = true; let canEnter = hasPass || hasTicket;
Q4
if (score < 0 || score > 100) { console.log("Invalid"); }
Q5
let isSat = day === "Sat"; let isSun = day === "Sun"; let off = isSat || isSun;
Section E: Spot the Error
Q1
D — A single | is a different (bitwise) operator. OR needs two bars, so it should be console.log(sat || sun);
Q2
B — Each side of || must be a full condition. The right side is missing temp, so it should be temp > 35.
Q3
B — JavaScript does not use the word or. The OR operator is written ||, so it should be age < 5 || age > 65.
Q4
C — The condition of an if statement must be inside brackets. It should be if (hasPen || hasPencil) {
Q5
A — Boolean values are written in lowercase in JavaScript. True causes an error, so it should be true.