🛠 Flutter world will be ready by the end of September, 2024 🚀🔥
Learn Dart Programming
Dart Basics
Comments and Documentation in Dart

Comments and Documentation in Dart

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.

 
/// Returns the absolute value of the given [number].
 
num abs(num number) {
  if (number >= 0) {
    return number;
  } else {
    return -number;
  }
}
 

Conclusion

In this tutorial, we learned about comments and documentation in Dart. In the next tutorial, we will learn about variables in Dart.