Skip to content
Justice Tech School

Named and Optional Parameters

Curly braces make named parameters, square brackets positional optionals. required forces a name.

Example
String box({required int w, int h = 1}) => "${w}x$h";
String pad(String s, [int n = 3]) => s.padLeft(n, "*");
print(box(w: 3));
print(box(h: 2, w: 4));
print(pad("a"));

Exercise

Required named.

({ int w})

Quiz Test

What do braces declare?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.