Coding for All
Lesson 2: Constants with let
Constants with let Store a value that never changes.
1let message = "Hi there"
2print(message)
Terminal
$ swift main.swift
Hi there
Every line, explained
let message = "Hi there"
let creates a constant: a named box whose value is set once and can never change. Swift people reach for let by default: if a value never needs to change, locking it down prevents accidents. Here it creates message and locks in the text "Hi there".
print(message)
print(...) shows whatever is inside its round brackets in the terminal, then moves to a new line. All lowercase, both brackets needed, and no semicolon at the end; Swift doesn't use them. No quotes around message, so Swift prints what is stored in the constant, not the word message itself.