Constants and variables associate a name with a value of a particular type (such as the number 10 or the string "Hello"). The value of a constant can’t be changed once it’s set, whereas a variable can be set to a different value in the future.
Constants and variables must be declared before they’re used.
You declare constants with the
const keyword and variables with the
Here’s an example of how constants and variables can be used to track the number of login attempts a user has made:
const maximumNumberOfLoginAttempts = 10let currentLoginAttempt = 0
const n1 = 1; // i32const n2 = 1L; // i64const n3 = 1.0; // f64const n4 = 1.0f; // f32