Bird
0
0

What will be the output of this Ruby code?

medium📝 Predict Output Q13 of 15
Ruby - Operators and Expressions
What will be the output of this Ruby code?
value = 0
if value
  puts "Truthy"
else
  puts "Falsy"
end
ANo output
BFalsy
CError
DTruthy
Step-by-Step Solution
Solution:
  1. Step 1: Identify the value and condition

    The variable value is assigned 0. The if value checks if value is truthy.
  2. Step 2: Recall Ruby truthy rules

    In Ruby, 0 is truthy, so the if branch runs.
  3. Final Answer:

    Truthy -> Option D
  4. Quick Check:

    0 is truthy in Ruby [OK]
Quick Trick: Remember 0 is truthy in Ruby, unlike some languages [OK]
Common Mistakes:
  • Assuming 0 is falsy like in other languages
  • Expecting else branch to run
  • Confusing output with error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes