Essential JavaScript
Introduction
JavaScript Basics
Numbers
Strings
Logic
Variables
Loops
Objects
Arrays
Going Further
Essential JavaScript
Introduction
JavaScript Basics
Numbers
Strings
Logic
Variables
Loops
Objects
Arrays
Going Further
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
I know which operators go first when there are both math and comparison operators
I can compare the result of two math equations in JavaScript
I know what values can be returned from a comparison operator
Code Editor
Click "Run Code" to execute your JavaScript in a secure sandbox and see the output below.
Console Output
0 output lines