Bird
0
0

What is the output of this Ruby code?

medium📝 Predict Output Q13 of 15
Ruby - Operators and Expressions
What is the output of this Ruby code?
puts (true || false) && !false
Anil
Bfalse
Ctrue
DSyntaxError
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate inside parentheses

    true || false is true because at least one side is true.
  2. Step 2: Evaluate the NOT operator

    !false is true because NOT false is true.
  3. Step 3: Evaluate the AND operator

    Now we have true && true, which is true.
  4. Final Answer:

    true -> Option C
  5. Quick Check:

    (true || false) && !false = A [OK]
Quick Trick: Evaluate parentheses, then !, then && [OK]
Common Mistakes:
MISTAKES
  • Evaluating && before ||
  • Forgetting to apply ! operator
  • Assuming false because of || false

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes