Dart Comments

Comments are the set of statements that are ignored by the Dart compiler during the program execution. It is used to enhance the readability of the source code. Generally, comments give a brief idea of code that what is happening in the code. We can describe the working of variables, functions, classes, or any statement that exists in the code. Programmers should use the comment for better practice. There are three types of comments in the Dart.

Types of Comments

Dart provides three kinds of comments

  • Single-line Comments
  • Multi-line Comments
  • Documentation Comments

Single-line Comment

We can apply comments on a single line by using the // (double-slash). The single-line comments can be applied until a line break.

Example -

Output:

Welcome to JavaTpoint

The // (double-slash) statement is completely ignored by the Dart compiler and retuned the output.

Multi-line Comment

Sometimes we need to apply comments on multiple lines; then, it can be done by using /*…..*/. The compiler ignores anything that written inside the /*…*/, but it cannot be nested with the multi-line comments. Let's see the following example.

Example -

Output:

Welcome to JavaTpoint

Dart Documentation Comment

The document comments are used to generate documentation or reference for a project/software package. It can be a single-line or multi-line comment that starts with /// or /*. We can use /// on consecutive lines, which is the same as the multiline comment. These lines ignore by the Dart compiler expect those which are written inside the curly brackets. We can define classes, functions, parameters, and variables. Consider the following example.

Syntax

Example -

Output:

Welcome to JavaTpoint

Next TopicDart Keywords