Dart Data Types
Since the Dart Constant is specified as an immutable object, it cannot be altered while the program is running. It is not possible to change the value once it has been initialized to the constant variable.
There are two definitions for the Dart constant.
It is useful when we wish to maintain the value throughout the entire program. To construct a constant variable, use the terms final and const. The data-type is used in combination with the keywords final and const. If we attempt to change the constant variable, Dart will raise an exception.
The compile-time constant is represented by a const keyword, and the final variable can only be set once.
The last term allows us to define the constant. Below is the syntax.
final const_name;
or
final data_type const_name
void main () {
final a = 10;
final b = 20;
print(a);
print(b);
}
10
20
The const keyword allows us to define constants. Below is the syntax.
const const_name
Or
const data_type const_name
void main() {
const name= "Peter";
print(name);
}
Peter
CodingAsk.com is designed for learning and practice. Examples may be made simpler to aid understanding. Tutorials, references, and examples are regularly checked for mistakes, but we cannot guarantee complete accuracy. By using CodingAsk.com, you agree to our terms of use, cookie, and privacy policy.
Copyright 2010-2024 by Refsnes Data. All Rights Reserved.