positional arguments dart 1

positional arguments dart

void main() {
  print(fullname("yo", "hope you have amazing day"));

// this fancy [] will do the job
String fullname(String fname, String lname, [String age = '23']) {
  return fname + lname + age;

Here is what the above code is Doing:
1. We have a function called fullname that takes two parameters, fname and lname.
2. We also have an optional parameter called age.
3. The optional parameter age has a default value of 23.
4. We return the concatenation of fname, lname, and age.
5. We call the function fullname and pass in two arguments, “yo” and “hope you have amazing day”.
6. We print the return value of the function.

Similar Posts