Bird
0
0

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:
  1. Step 1: Recall Ruby naming conventions

    Local variables start with lowercase letters or underscores. Constants start with uppercase letters.
  2. 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.
  3. Final Answer:

    Local variables start with a lowercase letter; constants start with an uppercase letter -> Option D
  4. Quick Check:

    Variable vs constant naming = lowercase vs uppercase [OK]
Quick Trick: Constants always start uppercase; locals lowercase [OK]
Common Mistakes:
  • Confusing local variables with constants
  • Using uppercase for local variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes