Bird
0
0

What is the output of this Ruby code?

medium📝 Predict Output Q4 of 15
Ruby - Operators and Expressions
What is the output of this Ruby code?
puts (false || true) && !false
Afalse
Btrue
Cnil
DSyntaxError
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the OR expression

    false || true evaluates to true.
  2. Step 2: Evaluate the NOT expression

    !false evaluates to true.
  3. Step 3: Evaluate the AND expression

    true && true evaluates to true.
  4. Final Answer:

    The output is true -> Option B
  5. Quick Check:

    (false || true) && !false = true [OK]
Quick Trick: Evaluate || and ! before && due to precedence [OK]
Common Mistakes:
  • Ignoring operator precedence
  • Confusing !false as false
  • Assuming false || true is false

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes