Bird
0
0

Which of the following is the correct syntax to assign 5 to variable a only if a is nil or false?

easy📝 Syntax Q12 of 15
Ruby - Operators and Expressions
Which of the following is the correct syntax to assign 5 to variable a only if a is nil or false?
Aa ||= 5
Ba =|| 5
Ca =| 5
Da =|= 5
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct operator syntax

    The correct Ruby operator for conditional assignment is ||=, not any variation with single or misplaced symbols.
  2. Step 2: Match syntax to options

    Only a ||= 5 uses ||= correctly as a ||= 5.
  3. Final Answer:

    a ||= 5 -> Option A
  4. Quick Check:

    Correct syntax = a ||= 5 [OK]
Quick Trick: Remember ||= has two vertical bars before equals [OK]
Common Mistakes:
MISTAKES
  • Using single | or misplaced symbols
  • Confusing with assignment =
  • Typing extra or missing characters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes