The “let” keyword in swift
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.
I am happy to share with this article with you. If you’ve enjoyed this article, do show support by giving a few claps 👏_ . Thanks for your time and make sure to follow me or drop your comment below_ 👇