A function declares its parameter and return types. return exits with a value.

Program

Play the program to add tax to a subtotal.

functions.dart
Replay: real traced execution (multi-file project)
int addTax(int price) {
  return price + price ~/ 10;
}

void main() {
  var subtotal = 25;
  var total = addTax(subtotal);
  print(total);
}
  1. subtotal ← 25

    5void main() {6  var subtotal = 25;7  var total = addTax(subtotal);
    values this step25subtotal
  2. call ← addTax(25)

    6var subtotal = 25;7var total = addTax(subtotal);8print(total);
    values this stepaddTax(25)call25subtotal
  3. return value ← 27

    1int addTax(int price) {2  return price + price ~/ 10;3}
    values this step27return value25price
  4. total ← 27

    6var subtotal = 25;7var total = addTax(subtotal);8print(total);
    values this step27total
  5. print(total);

    7  var total = addTax(subtotal);8  print(total);9}
    output27
    values this step27total
typed signature `int addTax(int price)` declares parameter and return types.
return `return` exits the function with a value.
integer division `price ~/ 10` is integer division for whole-cent rounding.