0
Can anyone tell when to use keyword var and keyword let?
8 Answers
+ 4
You should use "let" when you sure that containing value wouldn't change. It is a constant (like number Pi or else). "let" help us use system memory better
+ 2
var is a variable , which changes
but let is a constant , which doesn't change
+ 1
var declares a variable whose contents can be changed whereas let declares a constant that connot be changed (i.e. let myFirstName = Scott vs var myFavoriteColorToday = Blue). Its unlikely that I'll change my first name but it's quite possible that I might choose a new favorite color.
+ 1
let will be used when you are sure there is no change in value like universal truth or mathematical equations for example Ï=3.14, it will never change.
var will be used for normal variables
+ 1
simply, (let) is used when you define a constant wich eventually will hold a fixed value. and var is used when you define a variable that will change its value
0
Basically, things like someone's age is "var", someone's gender is a "let"
0
let Ï = 3.14 // It is a constant and we should use let keyword to avoid changing it by accident or sonething like that.
0
If you use let, the value can't be changed
If you use var, it can