
- Dart Programming Tutorial
- Dart Programming - Home
- Dart Programming - Overview
- Dart Programming - Environment
- Dart Programming - Syntax
- Dart Programming - Data Types
- Dart Programming - Variables
- Dart Programming - Operators
- Dart Programming - Loops
- Dart Programming - Decision Making
- Dart Programming - Numbers
- Dart Programming - String
- Dart Programming - Boolean
- Dart Programming - Lists
- Dart Programming - Lists
- Dart Programming - Map
- Dart Programming - Symbol
- Dart Programming - Runes
- Dart Programming - Enumeration
- Dart Programming - Functions
- Dart Programming - Interfaces
- Dart Programming - Classes
- Dart Programming - Object
- Dart Programming - Collection
- Dart Programming - Generics
- Dart Programming - Packages
- Dart Programming - Exceptions
- Dart Programming - Debugging
- Dart Programming - Typedef
- Dart Programming - Libraries
- Dart Programming - Async
- Dart Programming - Concurrency
- Dart Programming - Unit Testing
- Dart Programming - HTML DOM
- Dart Programming Useful Resources
- Dart Programming - Quick Guide
- Dart Programming - Resources
- Dart Programming - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Dart Programming - Returning Function
Functions may also return value along with the control, back to the caller. Such functions are called as returning functions.
Syntax
return_type function_name(){ //statements 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.
Example
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() { print(test()); } String test() { // function definition return "hello world"; }
It will produce the following output −
hello world