0Pricing
Dart Academy · Lesson

Default Values and required

Make parameters optional or mandatory.

Sensible Fallbacks

A default value is the fallback Dart uses when a caller skips a parameter. It saves callers from passing the obvious choice every time.

Default on Named Parameters

Give a named parameter a default with an equals sign. If the caller omits it, Dart quietly uses that value instead of null.

void greet({String name = "friend"}) {
  print("Hi $name");
}

All lessons in this course

  1. Declaring Functions and Return Types
  2. Positional vs Named Parameters
  3. Default Values and required
  4. Functions as First-Class Values
← Back to Dart Academy