in Technology by
What is the difference between Let and Var in swift?

1 Answer

0 votes
by

In swift language, we can declare a constant and variable using Let and Var keyword.

(i) Let: Let keyword is immutable, it’s used to declare a constant variable, and the constant variable cannot be changed once they are initialized.

For Example: let myAge = 25

We cannot change the value of age, you can declare the constant value of it only once using the let keyword.

(ii) Var: Var keyword is mutable, and is used to declare a variant variable. These variant variables can change the run time.

For Example:

var myName = “Dell”

we can change the value of name = “Apple”.

Related questions

0 votes
    Explain the difference between Swift vs Objective-C.?...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    Fill in the blanks: Let X be a random variable taking values x1, x2,..., xn with probabilities p1, p2, ..., ... . Then var (X) = Select the correct answer from above options...
asked Nov 19, 2021 in Education by JackTerrance
0 votes
    Let X represent the difference between the number of heads and the number of tails obtained when a coin is tossed 6 ... values of X? Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
    How to iterate a loop with index and element in Swift?...
asked Mar 9, 2021 in Technology by JackTerrance
0 votes
    How to change Swift version from 5 to 4 in Xcode?...
asked Mar 9, 2021 in Technology by JackTerrance
0 votes
    How do I see which version of Swift I'm using?...
asked Mar 9, 2021 in Technology by JackTerrance
0 votes
    Can we use both swift (.swft) and objective c (.h .m) in same xcode project ?...
asked Mar 9, 2021 in Technology by JackTerrance
0 votes
    How do I call Objective-C code from Swift?...
asked Mar 9, 2021 in Technology by JackTerrance
0 votes
    What is a GUARD statement? What is the benefit of using the GUARD statement in swift?...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    What is the use of double question mark “??” in swift?...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    What is a delegate in swift?...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    What is a Protocol in swift?...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    What is a dictionary in Swift ?...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    What are the control transfer statements that are used in iOS swift?...
asked Nov 30, 2020 in Technology by JackTerrance
...