The acronym you're looking for depends on what language you're writing in, but the concept is the same across all of them
If you're asking about mathematical operations in code, the acronym is PEMDAS (Parentheses, Exponents, Multiplication and Division, Addition and Subtraction) in the United States, or BODMAS (Brackets, Orders, Division and Multiplication, Addition and Subtraction) in the UK and other countries. Both describe the same rule: the order in which a computer evaluates a math expression when multiple operations appear in one line.
If you're asking about how code itself is evaluated — which parts run first, which variables get assigned before others — that's called operator precedence, and it's defined differently by each programming language. There's no single acronym for this, but understanding how your specific language handles it is essential to writing code that does what you intend.
Key Takeaways
- PEMDAS and BODMAS are the same rule with different regional names, and they apply to math expressions in any code.
- Operator precedence is language-specific: Python, JavaScript, Java, and C++ each have their own rules for which operations run first.
- When you're unsure about order of evaluation, parentheses always force the operation inside them to run first, regardless of language.
- Most bugs from evaluation order happen because a programmer assumed one operation would run before another without checking the language rules.
PEMDAS and BODMAS: The math rule that works in every language
PEMDAS stands for Parentheses, Exponents, Multiplication and Division (left to right), Addition and Subtraction (left to right). BODMAS is the same rule with different words: Brackets instead of Parentheses, and Orders instead of Exponents. Both tell you that if you write 2 + 3 * 4, the multiplication happens first, giving you 14, not 20.
This rule applies in Python, JavaScript, Java, C++, and virtually every other language. If you write a math expression, the computer will follow PEMDAS/BODMAS automatically. The catch is that this rule only covers math. It doesn't tell you what happens when you mix math with variable assignment, function calls, or logical operations — that's where operator precedence comes in.
Operator precedence: The language-specific rules that actually matter
Every programming language has a table that says "when you see these operations together, which one runs first?" This is called operator precedence. In Python, the exponent operator ** runs before multiplication. In JavaScript, the assignment operator = has lower precedence than almost everything else, which is why x = 5 + 3 adds first, then assigns. In Java, the ternary operator ? : has different precedence than in C++.
You can find your language's operator precedence table in its official documentation. Python's is in the Python docs under "operator precedence". JavaScript's is in the MDN Web Docs. Java's is in the Java Language Specification. These tables are not optional reading — they're the actual rules your code follows, and they're not always intuitive.
For example, in many languages, the bitwise AND operator & has lower precedence than the equality operator ==, which means a == b & c == d is read as (a == b) & (c == d), not a == (b & c) == d. If you don't know this rule, your code will do something you didn't expect.
Why parentheses are your safest tool
Parentheses force the operation inside them to run first, and this rule is the same in every language. If you're ever unsure about the order of evaluation, wrap the part you want to run first in parentheses. (2 + 3) * 4 always gives 20. a = (b + c) * d always adds first, then multiplies, then assigns.
This is not cheating or inefficient. Professional code uses parentheses liberally, even when they're not strictly necessary, because it makes the intent clear to anyone reading the code later — including yourself six months from now. A line like result = (x * y) + (a / b) is easier to understand than result = x * y + a / b, even though they do the same thing.
Common mistakes from misunderstanding evaluation order
The most common mistake is assuming that operations run left to right. They don't. In 2 + 3 * 4 - 5, the multiplication runs first (giving 12), then addition and subtraction run left to right (giving 2 + 12 - 5 = 9). If you assumed left to right, you'd expect (2 + 3) * 4 - 5 = 15, which is wrong.
Another common mistake is mixing up how different operators interact. In many languages, x = y = 5 works because assignment is right-associative, meaning it runs from right to left. So y = 5 happens first, then x = (result of y = 5). But in the same language, subtraction is left-associative, so 10 - 5 - 2 means (10 - 5) - 2 = 3, not 10 - (5 - 2) = 7.
A third mistake is forgetting that function calls have high precedence. In x = func() + 5, the function runs first, then its return value is added to 5, then the result is assigned to x. If you thought assignment happened first, you'd be confused about what x actually contains.
How to look up operator precedence for your language
Every language publishes an official operator precedence table. For Python, search "Python operator precedence" and go to the official Python documentation. For JavaScript, search "MDN operator precedence". For Java, search "Java operator precedence specification". For C++, search "C++ operator precedence cppreference".
These tables list every operator, show which ones have higher precedence than others, and note whether they're left-associative or right-associative. Bookmark the one for your language. When you're writing a complex expression and you're not 100% sure which part runs first, check the table before you run the code. It takes 30 seconds and saves you from a bug that might take 30 minutes to find.
Frequently Asked Questions
Is PEMDAS the same as BODMAS?
Yes. PEMDAS (Parentheses, Exponents, Multiplication and Division, Addition and Subtraction) and BODMAS (Brackets, Orders, Division and Multiplication, Addition and Subtraction) describe the same rule. The US uses PEMDAS, the UK and Commonwealth countries use BODMAS. Both tell you to do parentheses/brackets first, then exponents/orders, then multiplication and division together from left to right, then addition and subtraction together from left to right.
Does operator precedence change between Python and JavaScript?
Yes, it does. For example, Python's exponent operator ** is right-associative, so 2 ** 3 ** 2 means 2 ** (3 ** 2) = 512. JavaScript doesn't have a built-in exponent operator in older versions, and when it was added, it also made it right-associative. But other operators differ between languages. Always check your language's official table.
What happens if I use parentheses when I don't need them?
Nothing bad. Parentheses make the order explicit and the code clearer. Professional developers use them even when they're not required. (a + b) * c is easier to read than a + b * c, even though you know multiplication has higher precedence. Use them whenever it makes your intent clearer.
Can I rely on left-to-right evaluation if I'm not sure about precedence?
No. Left-to-right is not a universal rule. Exponents, multiplication, and many other operations have higher precedence than addition and subtraction, so they run first even if they appear later in the line. Always check your language's precedence table or use parentheses to be sure.