Comments

Comments are lines that are ignored by the Dart compiler. They are used to explain the code and make it easier to understand. Comments are also used to prevent execution when testing alternative code.

Dart supports both single-line and multi-line comments.

Single-line comments

Single-line comments start with //.

  
// This is a single-line comment.
  

Multi-line comments

Multi-line comments start with /* and end with */.

  
/* This is a multi-line comment.
   This is the second line.
   This is the third line.
*/
  

Documentation

Documentation comments are a special type of comment used to document the API of libraries, classes, and their members. Documentation comments begin with /// (three slashes) instead of //. For multi-line documentation, use /// at the beginning of each line, including the first. You can use Markdown notation in documentation comments.

  void main() {
    print(checkOdd(232));
}

/// Checks if the value of the given [number]. is odd and returns [true] if [number] is true
bool checkOdd(num number) {
  if (number%2 ==0) {
    return false;
  } else {
    return true;
  }
}
  

Put your cursor in the function name, and take a look at right-bottom of your sceen. The same documentation you have written is displayed.

code Try Yourself

Note: