Challenge - 5 Problems
Logical Operators Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of combined logical operators
What is the output of the following JavaScript code?
Javascript
const a = true; const b = false; const c = true; console.log(a && b || c);
Attempts:
2 left
💡 Hint
Remember that && has higher precedence than || in JavaScript.
✗ Incorrect
The expression evaluates as (a && b) || c. Since a && b is false, the result is false || true, which is true.
❓ Predict Output
intermediate2:00remaining
Logical NOT and OR combination
What will be logged to the console?
Javascript
const x = false; const y = true; console.log(!x || y);
Attempts:
2 left
💡 Hint
The ! operator flips the boolean value.
✗ Incorrect
!x is true because x is false, so true || true is true.
❓ Predict Output
advanced2:00remaining
Short-circuit evaluation with logical AND
What is the output of this code snippet?
Javascript
function test() { console.log('Function called'); return true; } const result = false && test(); console.log(result);
Attempts:
2 left
💡 Hint
Logical AND stops evaluating if the first operand is false.
✗ Incorrect
Since the first operand is false, test() is not called, so only false is logged.
❓ Predict Output
advanced2:00remaining
Logical OR with falsy values
What will be the output of this code?
Javascript
const val = 0 || '' || null || undefined || 'default'; console.log(val);
Attempts:
2 left
💡 Hint
Logical OR returns the first truthy value.
✗ Incorrect
All values before 'default' are falsy, so 'default' is returned.
🧠 Conceptual
expert2:00remaining
Understanding logical operator precedence and output
Consider the code below. What is the value of variable
result after execution?Javascript
const result = false || true && false || true;
Attempts:
2 left
💡 Hint
Remember that && has higher precedence than ||, so evaluate that part first.
✗ Incorrect
true && false is false, so expression becomes false || false || true, which evaluates to true.