Bird
0
0

Which of these Ruby variable names will cause a syntax error?

easy📝 Syntax Q12 of 15
Ruby - Variables and Data Types
Which of these Ruby variable names will cause a syntax error?
Atemp-var
BtempVar2
C_tempVar
Dtemp_var
Step-by-Step Solution
Solution:
  1. Step 1: Identify invalid characters in variable names

    Ruby variable names can only contain letters, digits, and underscores. Hyphens are not allowed.
  2. Step 2: Check each option for invalid characters

    temp-var has a hyphen, which causes a syntax error. The others are valid.
  3. Final Answer:

    temp-var -> Option A
  4. Quick Check:

    Hyphens cause syntax errors in variable names [OK]
Quick Trick: No hyphens allowed in variable names, use underscores instead [OK]
Common Mistakes:
  • Using hyphens instead of underscores
  • Confusing uppercase and lowercase letters
  • Starting variable names with digits

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes