Bird
0
0

Which of the following is the correct syntax to declare a variable in Swift Playgrounds?

easy📝 Syntax Q3 of 15
Swift - Basics and Runtime
Which of the following is the correct syntax to declare a variable in Swift Playgrounds?
Avariable name = "Alice"
Bvar name = "Alice"
Clet var name = "Alice"
Ddeclare var name = "Alice"
Step-by-Step Solution
Solution:
  1. Step 1: Recall Swift variable declaration syntax

    Swift uses 'var' to declare variables and 'let' for constants, followed by the variable name and value.
  2. Step 2: Check each option for correct syntax

    Only 'var name = "Alice"' matches Swift syntax; others use invalid keywords.
  3. Final Answer:

    var name = "Alice" -> Option B
  4. Quick Check:

    Variable declaration syntax = var name = value [OK]
Quick Trick: Use 'var' for variables and 'let' for constants [OK]
Common Mistakes:
  • Using 'variable' instead of 'var'
  • Combining 'let' and 'var'
  • Using 'declare' keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes