Bird
0
0

Which Ruby expression will return true for a truthy value?

easy📝 Conceptual Q2 of 15
Ruby - Operators and Expressions
Which Ruby expression will return true for a truthy value?
Aif 0 then true else false end
Bif false then true else false end
Cif nil then true else false end
Dif nil || false then true else false end
Step-by-Step Solution
Solution:
  1. Step 1: Recall truthy and falsy values in Ruby

    Only false and nil are falsy; everything else is truthy.
  2. Step 2: Evaluate each expression

    Options A and B check falsy values and return false. if 0 then true else false end checks 0, which is truthy, so returns true. if nil || false then true else false end uses nil || false which is falsy, so returns false.
  3. Final Answer:

    if 0 then true else false end returns true -> Option A
  4. Quick Check:

    Truthy check with 0 = true [OK]
Quick Trick: Only false and nil are falsy; 0 is truthy [OK]
Common Mistakes:
  • Assuming nil is truthy
  • Thinking false is truthy
  • Confusing 0 as falsy

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes