Basic Syntax in Dart
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
void main()
This line defines the main function, which is the entry point of a Dart program. Thevoidkeyword indicates that the function does not return a value.{
This opening brace marks the beginning of the main function's body.print('Hello, World!');
This line prints the string "Hello, World!" to the standard output (usually the screen). Theprintfunction is a built-in function in Dart for output.}
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
Mainandmainwould be considered different identifiers.