both let and var used to declare variable then what is the difference between Let and Var.
when to use Let. plzz explain with a example the main usage of Let keyword. thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Gokhul VarmanPosted Aug 1, 2017, 10:19 AM
Rajkiran SwainPosted Jun 16, 2017, 8:44 AM
let keyword in swift is used to declare constant value and immutable can never be changed once defined.
let name ="Kirit"
after you can change name = "Modi" then you got compiler error. So declare value of its only one time using let keyword.
Var :
var keyword is mutable in swift is used to declare variant value, That value can change at run time. it means can change it too many time.
var name = "Kirit"
You can changed name = "Modi" then successfully updated value of variable.
Vivek KumarPosted Jun 16, 2017, 5:54 AM
Ketan MokariyaPosted Jun 16, 2017, 5:51 AM
Sundaram SubramanianPosted Jun 16, 2017, 5:25 AM
The
letkeyword defines a constant:The
theAnswercannot be changed afterwards. This is why anythingweakcan't be written usinglet. They need to change during runtime and you must be usingvarinstead.The
vardefines an ordinary variable.