Ruby - Variables and Data TypesWhich of the following is a valid local variable name in Ruby?Auser_nameBUserNameCuser-nameD1usernameCheck Answer
Step-by-Step SolutionSolution:Step 1: Check the first character of each variable nameLocal variables must start with a lowercase letter or underscore. 'user_name' starts with 'u' which is lowercase.Step 2: Check for invalid charactersVariable names cannot contain hyphens or start with numbers. 'user-name' has a hyphen and '1username' starts with a number, so they are invalid.Final Answer:user_name -> Option AQuick 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 lettersUsing hyphens instead of underscoresStarting variable names with numbers
Master "Variables and Data Types" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Arrays - Array comparison and set operations - Quiz 7medium Hashes - Dig method for nested access - Quiz 9hard Methods - Implicit return (last expression) - Quiz 15hard Methods - Predicate methods (ending with ?) - Quiz 6medium Methods - Predicate methods (ending with ?) - Quiz 3easy Methods - Implicit return (last expression) - Quiz 12easy Operators and Expressions - Logical operators (&&, ||, !) - Quiz 4medium Operators and Expressions - Range operators (.. and ...) - Quiz 8hard Variables and Data Types - Integer and Float number types - Quiz 8hard Variables and Data Types - Symbol type and immutability - Quiz 1easy