Javascript · Booleans
Quizz
The full text of this chapter, to read or revisit. To practise, do the exercises.
▶ Do the exercisesExercise 1 — Quiz: Comparison Result
What will this code print?
let level = 25;
console.log(level >= 25);
Options
• ```true```
• ```false```
• ```25```
• ```undefined```
Hint : Think about what ```>=``` means. Does the comparison include equality or just greater than?
Exercise 2 — Quiz: Equality with Type Coercion
What does this comparison return?
console.log(false == 0);
Options
• ```true```
• ```false```
• ```0```
• ```TypeError```
Hint : Remember that ```==``` allows type coercion. How does JavaScript convert boolean values to numbers?
Exercise 3 — Quiz: AND Operator Logic
let hasWater = true;
let hasPlant = false;
console.log(hasWater && hasPlant);
Options
• ```true```
• ```false```
• ```null```
• ```undefined```
Hint : What does the AND operator require? Think about the truth table for ```&&```.
Exercise 4 — Quiz: Truthy or Falsy?
Which of these values is truthy?
Options
• ```[]``` (empty array)
• ```""``` (empty string)
• ```0```
• ```null```
Hint : Remember the 6 falsy values. Does any of these match those specific values?
Exercise 5 — Quiz: Short-Circuit with OR
let name = "Pyrochu";
let result = name || "Default";
console.log(result);
Options
• ```Pyrochu```
• ```Default```
• ```true```
• ```undefined```
Hint : With ```||```, what happens when the left side is truthy? Does it need to check the right side?
Exercise 6 — Quiz: Match Comparison Operators
Match each operator with its meaning:
Items to match
• >
• <=
• ===
• !==
Definitions
• Greater than
• Less than or equal to
• Strictly equal to
• Strictly not equal to
Exercise 7 — Quiz: NOT Operator
let isSleeping = true;
console.log(!isSleeping);
Options
• ```false```
• ```true```
• ```null```
• ```1```
Hint : What does the NOT operator do to boolean values? It flips them to their opposite.
Exercise 8 — Quiz: Strict Equality
console.log("100" === 100);
Options
• ```false```
• ```true```
• ```100```
• ```"100"```
Hint : Remember that ```===``` checks both value AND type. Are both sides the same type?
Exercise 9 — Quiz: OR Operator Result
let canEvolve = false;
let hasStone = false;
console.log(canEvolve || hasStone);
Options
• ```false```
• ```true```
• ```undefined```
• ```null```
Hint : The OR operator needs at least one truthy value. How many truthy values do you see?
Exercise 10 — Quiz: Identifying Falsy
How many of these values are falsy?
null
,
"hello"
,
undefined
,
42
Hint : Think about the 6 falsy values you learned. Which ones appear in this list?
Exercise 11 — Quiz: Truthy vs Falsy Classification
Match each value with its classification:
Items to match
• NaN
• "NaN"
• -1
• ""
• " "
Definitions
• Falsy
• Truthy
• Truthy
• Falsy
• Truthy
Exercise 12 — Quiz: Inequality Comparison
let damage = 45;
console.log(damage !== "45");
Options
• ```true```
• ```false```
• ```45```
• ```"45"```
Hint : Does ```!==``` perform type coercion? What does 'strictly not equal' mean?
Exercise 13 — Quiz: Short-Circuit AND
How many messages will be printed?
false && console.log("Message 1");
true && console.log("Message 2");
true && console.log("Message 3");
Options
• 2 messages
• 3 messages
• 1 message
• 0 messages
Hint : Think about short-circuit evaluation with ```&&```. When does the right side execute?
Exercise 14 — Quiz: Type Coercion Surprise
What does this comparison return?
console.log(true == 1);
Options
• ```true```
• ```false```
• ```1```
• ```undefined```
Hint : Remember that ```==``` allows type coercion. What number does ```true``` convert to?
Exercise 15 — Quiz: Combining Operators
let hp = 80;
let level = 15;
console.log(hp > 50 && level < 20);
Options
• ```true```
• ```false```
• ```80```
• ```15```
Hint : Evaluate each comparison separately, then apply the ```&&``` logic. What does AND require?
Exercise 16 — Quiz: Logical Operators Meaning
Match each operator with its function:
Items to match
• &&
• ||
• !
• ===
Definitions
• Returns true if both conditions are true
• Returns true if at least one condition is true
• Inverts the boolean value
• Checks equality without type coercion
Exercise 17 — Quiz: Double NOT Operator
let codemonName = "Florachu";
console.log(!!codemonName);
Options
• ```true```
• ```false```
• ```"Florachu"```
• ```undefined```
Hint : Double NOT converts any value to a boolean. Is the original value truthy or falsy?
Exercise 18 — Quiz: Less Than Comparison
let exp = 250;
let neededExp = 300;
console.log(exp < neededExp);
Options
• ```true```
• ```false```
• ```250```
• ```300```
Hint : Compare the two numbers. What does the ```<``` operator check for?
Exercise 19 — Quiz: Loose Equality Edge Case
console.log(null == undefined);
Options
• ```true```
• ```false```
• ```null```
• ```undefined```
Hint : This is one of JavaScript's special cases with ```==```. These two values have unique behavior.
Exercise 20 — Quiz: Empty String Behavior
let message = "";
console.log(message || "No message");
Options
• ```No message```
• ```""``` (empty string)
• ```true```
• ```false```
Hint : Is an empty string truthy or falsy? What does ```||``` do with falsy values?
Exercise 21 — Quiz: Equality Operator Results
Match each comparison with its result:
Items to match
• 5 == "5"
• 5 === "5"
• 0 == false
• 0 === false
• "" == 0
Definitions
• true
• false
• true
• false
• true
Exercise 22 — Quiz: Operator Precedence
let result = true || false && false;
console.log(result);
Options
• ```true```
• ```false```
• ```undefined```
• ```null```
Hint : Which operator has higher precedence: ```&&``` or ```||```? Evaluate in the correct order.
Exercise 23 — Quiz: Negative Numbers
console.log(Boolean(-5));
Options
• ```true```
• ```false```
• ```-5```
• ```undefined```
Hint : Which number is the only falsy number? Are negative numbers included in that?
Exercise 24 — Quiz: Short-Circuit Patterns
Match each pattern with its use case:
Items to match
• value || default
• condition && action
• !value
• !!value
Definitions
• Provide a default value
• Execute code conditionally
• Invert a boolean
• Convert to boolean
Exercise 25 — Quiz: Combining All Concepts
What will this complex expression return?
let hp = 0;
let name = "Aquachu";
let result = (hp > 0 || name) && !hp;
console.log(result);
Options
• ```true```
• ```false```
• ```"Aquachu"```
• ```0```
Hint : Break this down: evaluate the parentheses first, then apply ```&&```. Remember truthy/falsy behavior.
Back to the course