Essential JavaScript

Going Further

Order of Operations

Many math equations require a mix of operations like addition, subtraction, multiplication, and division.

JavaScript follows the standard order of operations for evaluating a math expression.

Take a look at the following examples:

ExpressionResult
2 + 3 * 414
8 - 4 / 26

Multiplication and division happen before addition and subtraction, even if they appear later in the expression.

Parentheses

Sometimes we need to manually declare which operations should happen first. We can do this by wrapping that operation in parentheses:

ExpressionResult
(2 + 3) * 420
(8 - 4) / 24

The same numbers and operators lead to a different result when we use parentheses to change the order of operations.

Learning Goals

  • I know which math operators go first in the order of operations

  • I can use parentheses to make an operation happen before those around it

Code Editor

Click "Run Code" to execute your JavaScript in a secure sandbox and see the output below.

Console Output

// Console output will appear here...

0 output lines