A lot of people can't figure out how to declare variable and constant in swift so today this tutorial i want to writing about constant and variable Only the first part of the statement is different: You declare constants using let, whereas you declare variables using var
you can use almost any character you like for constant and variable names including Unicode characters:

Cannot assign to value: number is a let constant Constants are useful for values that aren’t going to change
you can use almost any character you like for constant and variable names including Unicode characters:
number = 4
let 🐶🐮 = "dog cow"
once you have declared a constant or variable of a certain type ,you contain type ,you can't redeclare it again with the same name or change it to store values of a different type.Nor can you change a constant into a variable or a variable into constant
you can change the value of an existing variable to another value of compatible type in this example ,the value of "variableNumber" is changed from " variableNumber"
var variableNumber:Int = 3
variableNumber = 4
unlike variable the value of a constant can't t be changed one it is set .trying to do so is reported as an error when you code compile

Cannot assign to value: number is a let constant Constants are useful for values that aren’t going to change
Comments
Post a Comment