Declarations with let and const
Learning objective
- Declare mutable and immutable values correctly.
Key syntax
let total: int = 0;
const pi: float = 3.1416;
Examples
- Use
letfor values that change in loops or state updates. - Use
constfor fixed values such as config constants.
Common mistakes
- Redeclaring a symbol in the same scope.
- Reassigning a
constvariable.
Suggested practice
- Refactor a script to replace magic numbers with
constvalues.
Related
- types-and-collections
- diagnostics