Arithmetic and Operator Precedence
Add, subtract, multiply, divide, and group.
Arithmetic and Operator Precedence is a free Dart Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Dart Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Math Is Built In
Dart speaks math out of the box. You write numbers and symbols, and the arithmetic operators compute the result for you. Let us add it up. ➕
Addition and Subtraction
The + operator adds and - subtracts. They work just like on paper, and the answer is a number you can store or print.
void main() {
print(8 + 5); // 13
print(8 - 5); // 3
}Multiplication
Use the asterisk * to multiply two numbers. There is no times sign on the keyboard, so the star does that job everywhere in Dart.
void main() {
print(6 * 7); // 42
}Division Gives a double
The / operator always returns a double, even when the numbers divide evenly. So 10 / 2 is 5.0, not 5.
void main() {
print(10 / 2); // 5.0
}The Remainder Operator
The % operator gives the remainder after division. It is perfect for checking even numbers or wrapping values around a limit.
void main() {
print(17 % 5); // 2
}Precedence: Times Before Plus
Dart follows math rules: multiplication and division run before addition and subtraction. So 2 + 3 * 4 is 14, not 20.
void main() {
print(2 + 3 * 4); // 14
}Group With Parentheses
Wrap part of an expression in parentheses to force it first. They make your intent obvious and override the default order.
void main() {
print((2 + 3) * 4); // 20
}Left-to-Right at Equal Rank
When operators share the same precedence, Dart evaluates them left to right. So 20 - 5 - 3 becomes 12, reading in order.
void main() {
print(20 - 5 - 3); // 12
}Unary Minus
A single - before a value negates it. This unary minus binds tightly, flipping the sign before other math happens around it.
void main() {
print(-5 + 3); // -2
}Combining It All
Real expressions mix operators freely. Dart applies precedence and your parentheses to reach one clear, predictable answer every time. ✨
void main() {
print(10 + 4 * 2 - 6 / 3); // 16.0
}Keep It Readable
Even when precedence is on your side, adding parentheses for clarity is good style. Future you will thank present you for the hint.
Quick Check
Time to test your sense of operator order.
Recap
You can add, subtract, multiply, divide, and find remainders. Remember precedence, and use parentheses to make order crystal clear. 🎉
Frequently asked questions
Is the “Arithmetic and Operator Precedence” lesson free?
Yes — the full text of “Arithmetic and Operator Precedence” is free to read here on the web, and the Dart Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Dart Academy course, upgrade to CoddyKit PRO.
What will I learn in “Arithmetic and Operator Precedence”?
Add, subtract, multiply, divide, and group. You practise Dart Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Dart Academy?
No prior experience is required. Dart Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Arithmetic and Operator Precedence” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Dart Academy lesson?
Yes. Every Dart Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Arithmetic and Operator Precedence
- int vs double and Integer Division
- Parsing and Converting Numbers
- The dart:math Toolkit