Functions in Dart

A function in Dart is a block of code that performs a specific task and can be called or invoked from other parts of the program. Functions can take zero or more parameters and can return a value. They are used to organize and modularize code, making it easier to read, maintain, and reuse.

Note :

  • function_name() - The function name should be unique in dart, and same rules apply for the identifiers.
  • parameter_list - Parameter for passing value to the function which is optional.
  • return_type - Type of return value at end of function.

Projects

1. Sum of Two numbers

Write a function that returns the sum of two numbers.

  • Accept two numbers as parameters
  • Return sum of the given input

2. Reverse

Write a function that returns the reverse of a string.

3. Palindrome

Use the reverse function together to write another function that accepts a word and returns true if the word is a palindrome and false otherwise.

4. Factorial

Write a function that accepts a number and returns the factorial of that number. The factorial of a number is the product of all the integers from 1 to that number.

Resources