Bird
0
0

What is wrong with this Swift code?

medium📝 Debug Q14 of 15
iOS Swift - Swift Language Essentials
What is wrong with this Swift code?
let age = 25
age = 30
ACannot assign to value: 'age' is a constant
BMissing semicolon after 25
CVariable 'age' not declared
DSyntax error: let cannot be used
Step-by-Step Solution
Solution:
  1. Step 1: Identify declaration type

    age is declared with let, making it a constant.
  2. Step 2: Understand reassignment error

    Trying to assign a new value to a constant causes a compile-time error: "Cannot assign to value: 'age' is a constant".
  3. Final Answer:

    Cannot assign to value: 'age' is a constant -> Option A
  4. Quick Check:

    let constants cannot be changed [OK]
Quick Trick: let means constant; reassignment causes error [OK]
Common Mistakes:
  • Thinking semicolon is required
  • Confusing let with var
  • Ignoring reassignment rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes