Skip to content
AgileLogics
4 min read

How Dart Code Runs

Prerequisites: Your first Dart program

Dart can run your code in two ways:

  • JIT (just-in-time) compilation — used by dart run and by Flutter during development. Code is compiled as it runs, which starts quickly and makes hot reload possible.
  • AOT (ahead-of-time) compilation — used for release builds and dart compile exe. The whole program is compiled to native machine code in advance, so it starts fast and runs fast.

For the web, Dart compiles to JavaScript or WebAssembly instead.

Real-world analogy: JIT is a live interpreter at a rehearsal — flexible, and quick to try changes. AOT is the printed script for opening night — prepared in advance for the best performance.

Errors appear before anything runs

Dart checks your whole program before running it, so many mistakes are caught up front:

void main() {
  print('This line would run');
  int age = 'twenty';
}
hello.dart:3:13: Error: A value of type 'String' can't be assigned to a variable of type 'int'.
  int age = 'twenty';
            ^

Nothing is printed — the program never started. The message gives the file, line (3), column (13), and the problem. Your editor shows the same errors as you type, thanks to the Dart analyzer.

Runtime errors

Some problems only show up while the program runs:

void main() {
  print('Start');
  print(int.parse('abc'));
}
Start
Unhandled exception:
FormatException: Invalid radix-10 number (at character 1)
abc
^

The first line ran, then the program stopped with an exception. (The real output also includes a stack trace — the chain of function calls that led there.) You'll learn to handle exceptions in Level 2.