Mobile Development Swift Subjective
Oct 04, 2025

Explain the difference between var and let in Swift.

Detailed Explanation
The difference var let relates to mutability in Swift.\n\n• **var (Variable):**\n• Creates a mutable variable\n• Value can be changed after declaration\n• Used when you need to modify the value\n\n• **let (Constant):**\n• Creates an immutable constant\n• Value cannot be changed after initialization\n• Preferred for values that won't change\n• Better performance and safety\n\n**Examples:**\n\nvar age = 25\nage = 26 // ✅ Valid - can change\n\nlet name = "John"\n// name = "Jane" // ❌ Error - cannot change\n\nlet numbers = [1, 2, 3]\nnumbers.append(4) // ✅ Valid - array content can change\n
Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback