Today you will learn the difference between constants and variables.
You will see the difference between constants and variables, as you look at the picture below.
Before you can use your constants and variables, you need to declare them.
To declare a variable, you use the expression var.
var ActualWeather = "Sunny"
A constant is declared through the keyword let.
let UmbrellaColor = "Red"
Other types of values
At the moment, we just stored a String in a constant and variable. In the following, you will learn which other types of values can be stored.
Boolean (Can assume the following values: true or false)
var Visible = false
let TheEarthisasphere = true
Integer (Can just assume integers)
max properties (The significance of
max properties reveal itself, after you read the paragraph about type annotations):
var Currenttemperature = 25
let Lastbillingamount = 10
Double (Can assume integers and decimal numbers)
var Testvalue1 = 2.44
let Testvalue2 = 5
Float (Can assume integers and decimal numbers)
var Testvalue3 = 3
let Testvalue4 = 7.86
If you have to calculate with decimal numbers, remember that a Double is more precise than a Float!
If you are sure about the kind of values the constant or variable should store, you can use a type annotation:
var Visible:Bool = true
var Text:String = "This is a sample text"
var Number:Int = 8 or
var Number:Int8 = 5
var Firstdecimalnumber:Double = 2.1
var Seconddecimalnumber:Float = 2.4