- 01Setting up (what you'll need)
- 02Your first output (print)
- 03Variables and types (var and annotations)
- 04Null safety (? and !)
- 05Branching (the if statement)
- 06Repeating (the for loop)
- 07Writing your own function
- 08Repeating (the while loop)
- 09Working with lists (List)
- 10Working with maps (Map)
- 11Classes (object orientation)
- 12Constructors
- 13Inheritance
- 14Named arguments
- 15Asynchronous work (Future, async, await)
- 16Working with strings
- 17The switch statement
- 18The ternary operator
- 19Extension methods
- 20[Project] Build a small inventory system
Variables and types (var and annotations)
This lesson covers the basics of declaring variables in Dart.
You can let Dart infer the type with var, or state it explicitly as String, int, and so on. Once the type is settled, no value of another type can be assigned.
The sample code declares two variables — String name = 'Alice'; and int age = 14; — and builds a message with string interpolation, the '$variableName' notation.
A common early stumble is the interpolation syntax itself. A plain $ is enough to embed a variable, as in 'Hello, $name', but to embed a whole expression such as a calculation you need the dollar-sign-plus-braces form.
In professional work, string interpolation comes up constantly when assembling the text shown in a user interface.
๐งช This site can't compile or run Dart directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
