Variables
- Definition:
- Naming Rules:
Contain alphabets & numbers.
Spaces, special character (except the underscore _) and the dollar sign ($) are not allowed
Cannot begin with a number
Cannot be Reserved Keywords
- Syntax:
- Types:
To store a value in the computer memory we need an identifier (variable name) that refers to the memory location of this value. The value can be changed during the execution of the program.
Reserved Keywords : are the words predefined by the compiler like: for, get, null, true, void…
Before using the variable, it’s necessary to declare it:
we can initial it with a value or it will take the default value “null”:
Dart detect the variable type with the initial value.
We can optionally provide a type to ensures the data types of the variable:
For multiple variables declarations:
Note: ( = ) is called the assignment operator that gives to the variable in the left the value of the expression in the right.
Type | Example |
---|---|
Integer | int count = 32; |
Double | double average = 3.14; |
String | String name = ”john”; |
Boolean | bool isReady = true; |
List | List nums = [13, 7, 34]; |
Map | Map couple = {“husband”:”Mario”, ”wife”:”Diana”} |
Runes | var heart = '\u2665'; |