Every Dart program runs from main. String interpolation with $name builds output without + concatenation.

Program

Play the program to watch a name flow into a greeting and print.

hello.dart
Replay: real traced execution (multi-file project)
void main() {
  var name = 'Ada';
  var greeting = 'Hello, $name!';
  print(greeting);
}
  1. name ← Ada

    1void main() {2  var name = 'Ada';3  var greeting = 'Hello, $name!';
    values this stepAdaname
  2. greeting ← Hello, Ada!

    2var name = 'Ada';3var greeting = 'Hello, $name!';4print(greeting);
    values this stepHello, Ada!greetingAdaname
  3. print(greeting);

    3  var greeting = 'Hello, $name!';4  print(greeting);5}
    outputHello, Ada!
    values this stepHello, Ada!greeting

Follow the Greeting

  1. name starts as Ada.
  2. The greeting text uses the current name.
  3. greeting becomes Hello, Ada!.
  4. The program prints Hello, Ada!. | value | result | | --- | --- | | name | Ada | | greeting | Hello, Ada! | | stdout | Hello, Ada! |
main `void main()` is the program entry point.
var `var` infers the variable's type from the initializer.
interpolation `'$name'` embeds a value inside a string.

Exercise: hello.dart

Reproduce Hello, Ada!, then identify which value is inserted into the greeting.