In swift, we use the let
keyword to declare a constant variable, a constant is a variable that once declared, the value can not be changed.
Declaring constants
We can declare a variable in swift like below:
let myAge: Int = 27
Notice the let
keyword above, we use it to denote that myAge
is a constant and should hold the integer 27
. Unlike variable declared using the var
keyword, we cannot change the value of a constant once it has been assigned.
A constant is very similar to a variable except it value cannot be changed when declared.
Summary
It’s important that you keep the following in mind. You can declare a constant with the let
keyword, constant have the same properties as a variable (var) which include type annotation, naming convention etc., except once a value has been assigned, the value cannot be changed
Top comments (1)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.