Essential JavaScript

Order of Operations 2

In a previous lesson we covered the order of operations. This is a rule of math that says which operators act first.

In JavaScript and other programming languages, there are more operators than the basic math operators:

  • addition
  • subtraction
  • multiplication
  • division
  • modulus

We also have the comparison operators:

  • greater than
  • less than
  • equal to
  • greater than or equal to
  • less than or equal to

These operators go after the math operators.

Try this code:

7 - 3 < 2 + 4

First JavaScript evaluates the math operators, then it evaluates the comparison operator against the new values:

7 - 3 < 2 + 4 // original expression
4 < 6 // after math operators are evaluated
true // after comparison operator is evaluated

Remember that math operators always go first, then the results are compared.

When the comparison operator runs, the result is true or false as always.


Learning Goals

Code Editor