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
- Declaring Functions and Return Types
- Positional vs Named Parameters
- Default Values and required
- Functions as First-Class Values