Menu
Coddy logo textTech

Final Variables

Part of the Fundamentals section of Coddy's Dart journey — lesson 11 of 94.

In Dart, final variables cannot be changed after initialization. They create constants in your program.

void main() {
  final name = 'Dart Programmer';
  print(name);
}

You can specify types or let Dart infer them. Attempting to reassign final variables causes errors:

void main() {
  final score = 100;
  // score = 200;  // Error: Can't reassign final variables
}
challenge icon

Challenge

Beginner

In this challenge, you'll learn about final variables in Dart. A final variable can only be set once and cannot be changed after initialization.

Complete the following tasks:

  1. Create a final integer variable named releaseYear with the value 2011 (the year Dart was first released)
  2. Create a final string variable named creator with the value "Google"
  3. Create a final boolean variable named isCompiledLanguage with the value true
  4. Print all three variables with descriptive labels exactly as shown in the expected output

Your output should look exactly like this:

Dart was released in: 2011
Dart was created by: Google
Is Dart a compiled language? true

Cheat sheet

In Dart, final variables cannot be changed after initialization. They create constants in your program.

final name = 'Dart Programmer';
final score = 100;

You can specify types or let Dart infer them. Attempting to reassign final variables causes errors:

final score = 100;
// score = 200;  // Error: Can't reassign final variables

Try it yourself

void main() {
  // Declare your final variables here
  final int releaseYear = ?;
  final String creator = ?;
  final bool isCompiledLanguage = ?;
  
  // Print the variables with labels
  print("Dart was released in: " + releaseYear.toString());
  print("Dart was created by: " + creator);
  print("Is Dart a compiled language? " + isCompiledLanguage.toString());
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals