Bird
0
0

Which of the following is a valid local variable name in Ruby?

easy📝 Conceptual Q11 of 15
Ruby - Variables and Data Types
Which of the following is a valid local variable name in Ruby?
Auser_name
BUserName
Cuser-name
D1username
Step-by-Step Solution
Solution:
  1. Step 1: Check the first character of each variable name

    Local variables must start with a lowercase letter or underscore. 'user_name' starts with 'u' which is lowercase.
  2. Step 2: Check for invalid characters

    Variable names cannot contain hyphens or start with numbers. 'user-name' has a hyphen and '1username' starts with a number, so they are invalid.
  3. Final Answer:

    user_name -> Option A
  4. Quick Check:

    Valid local variable = user_name [OK]
Quick Trick: Local variables start lowercase or underscore, no hyphens or digits first [OK]
Common Mistakes:
  • Starting variable names with uppercase letters
  • Using hyphens instead of underscores
  • Starting variable names with numbers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes