What are Comments?
In Dart, comments are used to add explanations and annotations to your code, to help others (or yourself) understand what the code does. Comments are ignored by the Dart compiler and do not affect the behavior of your program. There are two types of comments in Dart:
1. Single-line comments (// Single-Line Comment Here)
2. Multi-line comments. (/* Multiline Comments Here*/)
3. Documentation Comment (/// Documentation Comment)
Single-line comments start with //
and continue to the end of the line:
// This is a single-line comment
print('Hello, World!');
Multi-line comments are enclosed between /*
and */
:
/*
This is a
multi-line comment
*/
print('Hello, World!');
Documentation comments will start from ///:
///This is Documentation Comment
print('Hello, World!');
Keypoint
It’s a good practice to use comments in your code to provide information about what the code does, how it works, and what it’s used for. This helps make your code more readable and easier to understand, especially for other people who might work on the code in the future.