0xOpenBytes

SwiftLet #03: Var

Var is the keyword to define a variable.

var variable: String

variable = "👋"

print(variable) // 👋

variable = "ðŸ˜ą"

print(variable) // ðŸ˜ą

Example 1

Some types allow for the use of different operators! So far we have only used the assignment operator (=). For this example we will try using the addition operator (+).

var variable: String

variable = "👋"

print(variable) // 👋

variable = variable + "ðŸ˜ą"

print(variable) // ðŸ‘‹ðŸ˜ą

Example 2

var variable: [String]

variable = ["👋"]

print(variable) // ["👋"]

variable.append("ðŸĪŠ")

print(variable) // ["👋", "ðŸĪŠ"]
Tagged with: