What are the comments in Dart?

Comments are used to explain and add notes in code. The compiler ignores the commented code during the time of execution of the program.

📅 Wed Nov 13 20242 min
image

Type of comments in Dart

1.Single line comment

Single-line comments are used to comment single line of code. 
 They start with //

// Welcome to Deveraa!
print("Welcome to Deveraa!"); 

2.Multi-line Comments

Multi-line comments are used to comment out multiple lines of code. They start with /* and end with */. 

/* 
This is a multi-line comment.
Welcome to Deveraa!
*/
print("Welcome to Deveraa!"); 

3.Documentation Comments

a. Documentation Comments are multi-line or single-line comments that begin with /// or /**.
b. These comments are used inside the documentation and also called Doc Comments

Single-line documentation comment:

/// This is a documentation comment for a function
void myFunction() {
  // function code
}

Multi-line documentation comment:

/**
 * This is a detailed documentation comment.
 * It can span multiple lines and is often used
 */
class MyClass {
  // class code
}

Summary:

1. // — Single-line comment
2. /* */ — Multi-line comment
3. /// — Documentation comment (for single-line descriptions)
4. /** */ — Multi-line documentation comment (for detailed descriptions)

Related Posts

What is Flutter...??

Flutter is an open-source UI software development kit for building natively compiled applications for mobile, web, and desktop from a single codebase. It works on the Dart programming language and is famous for developing fast, expressive and flexible UIs and high performance output.

2 min

What is Dart in Flutter..??

Dart is the programming language which Flutter adopted to build a cross-platform application. Google has developed this language and optimized in UI, and it is suitable for the fast development of visually rich applications on Flutter.

2 min

What is main in Flutter...??

Every programming language has an entry point from which the main execution of the code begins. Dart has this point with the main() function-that is where the program first looks to start executing code.

2 min

What is print()..??

The print statement is used in Dart to display output to the console. It is very helpful for debugging so you can see the value of variables or whether particular parts of your code are running as you expect them to.

2 min

Semicolon in Dart

In Dart, a semicolon (;) is used to terminate a statement. It signals the end of the statement and is essential for proper code execution. Without a semicolon, the code will produce a syntax error.

5 min

Identifiers in Dart

In Dart, identifiers are used to name variables, functions, classes, methods, parameters, and other components in your code. These names can include letters, digits, underscores (_), and dollar signs ($), but they must adhere to specific rules for valid naming

2 min