Bird
0
0

What is wrong with this Swift code?

medium📝 Debug Q7 of 15
Swift - Variables and Constants
What is wrong with this Swift code?
let value
value = 5
AType inference requires explicit type here
BConstant must be initialized at declaration
CVariable name value is invalid
DCannot assign Int to a constant
Step-by-Step Solution
Solution:
  1. Step 1: Understand let constant rules

    Constants declared with let must be assigned a value immediately.
  2. Step 2: Identify error in code

    value is declared without initialization, then assigned later, which is invalid.
  3. Final Answer:

    Constant must be initialized at declaration -> Option B
  4. Quick Check:

    let requires immediate initialization [OK]
Quick Trick: let constants need value when declared [OK]
Common Mistakes:
  • Trying to assign to let after declaration
  • Thinking variable name is invalid
  • Assuming type must be explicit here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes