Dart Basic Syntax


Dart Basic Syntax

In this tutorial, we will learn the basic syntax of Dart language. We will go through the key components of a simple Dart program.

Dart Program

void main() {
    print('Hello, World!');
}

Output

Hello, World!

Basic Syntax of a Dart Program

  1. void main()
    This line defines the main function, which is the entry point of a Dart program. The void keyword indicates that the function does not return a value.
  2. {
    This opening brace marks the beginning of the main function's body.
  3. print('Hello, World!');
    This line prints the string "Hello, World!" to the standard output (usually the screen). The print function is a built-in function in Dart for output.
  4. }
    This closing brace marks the end of the main function's body.

Key Points to Remember

  • All Dart statements must end with a semicolon (;).
  • The main function is the entry point of a Dart program.
  • Comments can be added using // for single-line comments or /* ... */ for multi-line comments.
  • Code blocks are enclosed in curly braces {}.
  • Dart is case-sensitive, meaning that Main and main would be considered different identifiers.