In Dart, variables are used to store and manipulate data. Dart is a statically typed language, which means that variables have types, and once a variable is declared with a certain type, it cannot hold values of any other type.
Types of Dart Varibles
1. var : This keyword is used for declaring variables where you want Dart to infer the type. For examplevar name = "John"; // Dart infers that name is a String
var age = 30; // Dart infers that age is an int
dynamic dynamicVariable = "Hello"; // Can hold any type of value
dynamicVariable = 10; // Now it's an int
final int x = 10;
const double PI = 3.14;
void main() {
var name = "Alice";
var age = 25;
print("Name: $name, Age: $age");
dynamic dynamicVariable = "Hello";
print(dynamicVariable); // Outputs: Hello
dynamicVariable = 10;
print(dynamicVariable); // Outputs: 10
final int x = 10;
// x = 20; // This will cause an error since x is final
const double PI = 3.14;
print(PI); // Outputs: 3.14
}