Junior — Middle
What is the purpose of using the const modifier in a programming language?
sobes.tech AI
Answer from AI
The const modifier in programming languages is used to declare immutable values or objects. In Flutter (Dart), const means that the value or object is created at compile time and cannot be changed during runtime.
This allows:
- Improved performance by creating constant objects once.
- Guarantee of data immutability.
Example of usage in Flutter:
const pi = 3.14;
const widget = Text('Hello', style: TextStyle(fontSize: 20));
Here, widget is created once and can be reused without additional costs.