final / const
Defines an immutable (constant) value.
Syntax
final name = value; // const name = value;
Description
final is assigned once and cannot be changed later. const is for values that are compile-time constants. Neither can be reassigned a second time.
Example
Loading editor…
Expected output
HexLibrary 3.14
When to use?
Values that will not change (constants, settings).
Common mistakes
- ⚠️ Assigning a second time to a final/const variable causes a compilation error.