• Guides
    • Getting started with Dart
  • Blog
  • FAQ
    • Dart
    • Flutter
  • Contact
  • Guides
    • Getting started with Dart
  • Blog
  • FAQ
    • Dart
    • Flutter
  • Contact
  • Getting Started with Dart
    • Dart Variables
    • Dart Operators
    • Dart Comments
  • Dart Data Types
    • Dart Strings
    • Dart Numbers
    • Dart Booleans
    • Dart Lists
    • Dart Maps
  • Control Flow
    • Dart if...else Statements
    • Dart switch Statement
    • Dart for Loop
    • Dart for...in Loop
    • Dart while and do...while Loops
    • break and continue Statements
  • Dart Functions
  • Dart Classes
  • Dart Objects
  • Dart Constructors
  • Dart Exceptions

Dart Comments

184 views 1

Written by Ajaya Shrestha
December 28, 2021

In this chapter, we will learn about comments in the dart, and why it is useful.


Dart Comments

Comments are texts that are ignored by the program. This is generally useful because this helps in making code easier to read and understand.

There are three kinds of comments that dart supports.

  1. Single-line Comments
  2. Multi-line Comments
  3. Documentation Comments

Single-line Comments

Single line comments in dart start with double slash ( // ). For example,

void main() {
// this is the single line comment
print(‘Hello World!);
}

Here,

 // this is the single-line comment

 is a comment. This line is ignored by the compiler.

These are used to provide short insights into the specific code line.


Double-line Comments

Double-line comments start with /* and end with */. Anything between them is considered as comments and ignored by the compiler.

For example,

void main() {
/* this is the multi line comment
hello world program
*/
print(‘Hello World!);
}

Here,

/* this is the multi-line comment
hello world program
*/

is a multi-line comment. These are generally used to explain the flow and process of the code.


Documentation Comments

Documentation comments start with three slashes. For example,

void main() {
/// this is the documentation comment
/// hello world program
print(‘Hello World!);
}

Here,

/// This is the documentation comment
/// hello world program

is the documentation comments.

The document comments are used for documenting the project or a package.


Why use Dart Comments?

When we write comments, it will be easier to understand the code in the future. It will also help other developers to understand the code, and what it does when they look at the comments.

However, that being said, the code should be well-structured and follow the best practices and the comment should just help in understanding what the particular code does.

Next chapter, We will learn about Dart Data Types.

Was this helpful?

1 Yes  No
Related Articles
  • Dart Constructors
  • Dart Exceptions
  • Dart Objects
  • Dart Classes
  • Control Flow
  • Dart Functions
Previously
Dart Operators
Up Next
Dart Data Types
flutter-dev-experts




FLUTTERGUIDE
FlutterGuide is an easy learning guide platform to help you build apps for any screen. The leading Dart/Flutter guides for getting started and become pro.
Guides
  • Private Documentation 1
  • Getting started with Dart 22
Categories
  • Firebase
  • Dart
  • iOS
  • API
  • Bloc
  • Flutter
  • Widgets
  • Mobile
  • State Management
  • Design
  • Animations
  • Flutter Designs
About
About Us
Guides
Blogs
FAQs
Contact
  • Privacy Policy
  • Terms & Conditions
  • Copyright 2022 Fawesome Apps. All Rights Reserved