What is the difference between a local variable and a constant in Ruby?
easy📝 Conceptual Q2 of 15
Ruby - Variables and Data Types
What is the difference between a local variable and a constant in Ruby?
ALocal variables and constants have no naming differences
BLocal variables start with an uppercase letter; constants start with a lowercase letter
CLocal variables start with a dollar sign; constants start with an underscore
DLocal variables start with a lowercase letter; constants start with an uppercase letter
Step-by-Step Solution
Solution:
Step 1: Recall Ruby naming conventions
Local variables start with lowercase letters or underscores. Constants start with uppercase letters.
Step 2: Match options with rules
Local variables start with a lowercase letter; constants start with an uppercase letter correctly states the difference. Options B, C, and D are incorrect based on Ruby rules.
Final Answer:
Local variables start with a lowercase letter; constants start with an uppercase letter -> Option D
Quick Check:
Variable vs constant naming = lowercase vs uppercase [OK]