Skip to main content
A single-line comment is a lexical construct initiated by the double forward-slash token (//). The Dart compiler ignores all characters following this token up to the end of the current line (EOL), treating the sequence as non-executable whitespace.

Syntax

// This text is ignored by the compiler.
int count = 0; // This text is also ignored.

Technical Characteristics

  • Tokenization: The comment begins immediately at the // sequence.
  • Scope: The comment extends from the start token until the next newline character (\n or \r\n). It does not span multiple lines.
  • Nesting: While // can technically appear inside a block comment (/* ... */), it has no special syntactic meaning there. Conversely, block comment delimiters (/*) appearing inside a single-line comment are ignored.
  • String Literals: If the // sequence appears within a string literal, it is parsed as string data rather than a comment initiator.
void main() {
  // var x = 5; -> The variable x is not declared.
  
  String url = "https://dart.dev"; // The // here is part of the string value.
}
Master Dart with Deep Grasping Methodology!Learn More