0
0
Javascriptprogramming~20 mins

Logical operators in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Logical Operators Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
Atrue
Bfalse
Cundefined
DTypeError
Attempts:
2 left
💡 Hint
Remember that && has higher precedence than || in JavaScript.
Predict Output
intermediate
2:00remaining
Logical NOT and OR combination
What will be logged to the console?
Javascript
const x = false;
const y = true;
console.log(!x || y);
Atrue
Bfalse
Cundefined
DSyntaxError
Attempts:
2 left
💡 Hint
The ! operator flips the boolean value.
Predict Output
advanced
2: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);
Atrue
Bfalse
CFunction called\nfalse
DReferenceError
Attempts:
2 left
💡 Hint
Logical AND stops evaluating if the first operand is false.
Predict Output
advanced
2:00remaining
Logical OR with falsy values
What will be the output of this code?
Javascript
const val = 0 || '' || null || undefined || 'default';
console.log(val);
A0
Bnull
Cdefault
Dundefined
Attempts:
2 left
💡 Hint
Logical OR returns the first truthy value.
🧠 Conceptual
expert
2: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;
ATypeError
Bfalse
Cundefined
Dtrue
Attempts:
2 left
💡 Hint
Remember that && has higher precedence than ||, so evaluate that part first.