Dart Functions | RRTutors

Dart Functions

Functions in dart are similar to those in JavaScript. 

It consists of the function name, return value, and parameters.

 

main(List<String> args) {

  var name = fullName('Chandu', 'Mouli');

  print(name);

}

 

String fullName(String firstName, String lastName) {

  return "$firstName $lastName";

}

 

return type is an option, if we can remove return type and function looks like below

 

main(List<String> args) {

  var name = fullName('Chandu', 'Mouli');

  print(name);

}

 fullName(String firstName, String lastName) {

  return "$firstName $lastName";

}

 

If the function having single line we can write it as

 

main(List<String> args) {

  var name = fullName('Chandu', 'Mouli');

  print(name);

}

 

fullName(String firstName, String lastName) => "$firstName $lastName";

Advertisements