Dart Programming - Returning Function

Functions may also return value along with the control, back to the caller. Such functions are called as returning functions.


return_type function_name(){  
   return value;  
  • The return_type can be any valid data type.

  • The return statement is optional. I not specified the function returns null;

  • The data type of the value returned must match the return type of the function.

  • A function can return at the most one value. In other words, there can be only one return statement per function.


Let’s take an example to understand how returning functions work.

  • The example declares a function test(). The function’s return type is string.

  • The function returns a string value to the caller. This is achieved by the return statement.

  • The function test() returns a string. This is displayed as output.

void main() { 
String test() { 
   // function definition 
   return "hello world"; 

It will produce the following output

hello world