Dart · Lesson 1 · On the house

Hello Dart

print, // comments, dart run, main, null-safe framing. Lesson 1 is free — on the house.

Lessons · Dart · Lesson 1 of 10 · On the house

Hello Dart

print, // comments, dart run, main, null-safe framing.

Illustration for Dart
Lesson 1 is on the house.

print writes a line to standard output (and adds a newline). It is the everyday way to show a value while you learn: print("hello");.

Line comments start with //. Block comments use /* ... */. Dart source files usually end in .dart.

A program starts in main. The common shape is void main() { ... }. Save as hello.dart and run with dart run hello.dart (SDK on your PATH).

Modern Dart is null-safe by default: ordinary types reject null unless you mark them nullable. You will use ? and related operators later; for now, write non-null values in main.

Misses: writing console.log or println, using # comments, or running python hello.dart / node hello.dart instead of dart run hello.dart.

hello

void main() {
  print("hello");
  // a line comment
}
Match this when you type.

Quiz

Which call writes a line in Dart?

Quiz

How do you start a single-line comment in Dart?

Quiz

How do you run a script named hello.dart?

Quiz

Where does a Dart program usually start?

Check

Match the still for: Hello Dart.

Open-book: the answers are on this page. Pass every quiz and check (5) to mark the lesson done. This visit: 0/5.