Variables & Data Types
let declares a constant; var declares a
variable you can reassign.
Example: preferring let by default
let name = "Ada"
var age = 21
print("\(name) is \(age) years old.")
Ada is 21 years old.
By now this should feel familiar: let here plays the
exact same role as JavaScript's const, Kotlin's
val, and Dart's final — every one of these
modern languages independently converged on "prefer an unreassignable
value by default" as good practice. Swift infers the type from the
assigned value, or you can write it explicitly:
let age: Int = 21. Note Swift's string interpolation uses
backslash-parenthesis \( ), not the dollar-brace
${ } or dollar-only $name styles other
languages in this tutorial use — a small but real syntax difference worth
remembering.
let name = "Ada"
var age = 21
print("\(name) is \(age) years old.")
Ada is 21 years old.