Variables in Dart

Variables in Dart

Primitive/Basic Variables in dart (int, String, double)

Here’s an example of creating a variable and initializing it:

Simple Variable

var name = 'Foo';

Variables store references. The variable called name contains a reference to a String object with a value of “Bob”.

Explicitly want to set the type? No problem

String Variable

String name = 'Foo';

Want to declare integers?

Integer variable

int count = 4;

Want to declare Floating point numbers?

Float/Double variable

double f = 1.0;

double is a language keyword

A simple program that uses variables

void main() { 
   int num=10; 
   double x = 10.0;
   String y = 'Hello World!';
   print(num); 
   print(x);
   print(y);
}

That's all!

Next we will look into the dart language keywords set and explore a few keywords that change the way variables behave.

See Const keyword in dart