Optional Parameters with Default Values

  • Post author:
  • Post category:Dart
  • Post comments:2 Comments
Optional Parameters with Default Values

In this guide, we will discuss Optional Parameters with Default Values. Function parameters can also be assigned values by default. However, such parameters can also be explicitly passed values.

Syntax

function_name(param1,{param2= default_value}) { 
   //...... 
} 

Example

void main() { 
   test_param(123); 
}  
void test_param(n1,{s1:12}) { 
   print(n1); 
   print(s1); 
}   

It should return the following output

123 
12 

Note − All required parameters in a function must occur before optional parameters.

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply