Bird
0
0

What will the following Ruby code output?

medium📝 Predict Output Q4 of 15
Ruby - Variables and Data Types
What will the following Ruby code output?
value = false
if value || nil
  puts "Yes"
else
  puts "No"
end
AYes
BNo
Cnil
DError
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition value || nil

    value is false, nil is also falsey, so false || nil is falsey.
  2. Step 2: Determine which branch runs

    Since condition is falsey, the else branch runs, printing "No".
  3. Final Answer:

    Yes -> Option A
  4. Quick Check:

    False or nil = falsey, prints No [OK]
Quick Trick: false || nil is falsey, triggers else branch [OK]
Common Mistakes:
MISTAKES
  • Assuming nil is true
  • Thinking false || nil is true
  • Confusing output with error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes