Bird
0
0

Identify the problem in this Ruby code:

medium📝 Debug Q7 of 15
Ruby - Variables and Data Types
Identify the problem in this Ruby code:
value = nil
if value == false
  puts "False"
else
  puts "Not false"
end
ACannot compare nil with false
BShould use '===' instead of '=='
Cnil is not equal to false, so else runs
DMissing parentheses in if condition
Step-by-Step Solution
Solution:
  1. Step 1: Understand comparison of nil and false

    In Ruby, nil == false is false because they are different objects.
  2. Step 2: Determine which branch runs

    Since condition is false, the else branch runs, printing "Not false".
  3. Final Answer:

    nil is not equal to false, so else runs -> Option C
  4. Quick Check:

    nil == false is false, else runs [OK]
Quick Trick: nil and false are different objects, not equal [OK]
Common Mistakes:
  • Assuming nil == false is true
  • Using wrong comparison operator
  • Syntax errors in if condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes