Dart by Example: Variables

  1. main() {
  2. // 'var' declares a variable. dartanalyzer infers the type.
  3. var a = "initial";
  4. print(a);
  5. // The type can also be declared:
  6. num b = 42;
  7. print(b);
  8. // final variables cannot be changed once declared
  9. final num c = 99;
  10. print(c);
  11. // const variables are compile-time constants
  12. const double d = 44.00;
  13. print(d);
  14. }
  15.  
  1. $ dart variables.dart
  2. initial
  3. 42
  4. 99
  5. 44.0

by @jryanio | source | license