Functions as first-class objects

You can pass a function as a parameter to another function. For example:

  1. void printElement(int element) {
  2. print(element);
  3. }
  4. var list = [1, 2, 3];
  5. // Pass printElement as a parameter.
  6. list.forEach(printElement);

You can also assign a function to a variable, such as:

  1. var loudify = (msg) => '!!! ${msg.toUpperCase()} !!!';
  2. assert(loudify('hello') == '!!! HELLO !!!');

This example uses an anonymous function.More about those in the next section.