Skip to content

Latest commit

 

History

History
469 lines (449 loc) · 12.7 KB

File metadata and controls

469 lines (449 loc) · 12.7 KB

Operators

[toc]


Order of Operations 🎗️

The order of operations or operator precedence, is the order by which the rules for operations are applied.

ℹ️ Note: Originally this table was posted in Section 4.6.3.2. of the Textbook.

🎗️ TODO: Add a Notes column later, or better yet add some superscripts and list out stuff after the table is complete.

The following table is ordered from highest (21) to lowest (1) precedence.

Precedence Operator Type Associativity1 Individual operators
21 Grouping n/a ( )
20 Member Access LTR .
20 Computed Member Access LTR [ ]
20 new (with argument list) N/A new ( )
20 Function Call LTR ( )
20 Optional chaining LTR ?.
19 new (without argument list) RTL new
18 Postfix Increment N/A ++
18 Postfix Decrement N/A --
17 Logical NOT RTL !
17 Bitwise NOT RTL ~
17 Unary Plus RTL +
17 Unary Negation RTL -
17 Prefix Increment RTL ++
17 Prefix Decrement RTL --
17 typeof RTL typeof
17 void RTL void
17 delete RTL delete
17 await RTL await
16 Exponentiation RTL **
15 Multiplication LTR *
15 Division LTR /
15 Remainder (Modulus) LTR %
14 Addition LTR +
14 Subtraction LTR -
13 Bitwise Left Shift LTR <<
13 Bitwise Right Shift LTR >>
13 Bitwise Unsigned Right Shift LTR >>>
12 Less Than LTR <
12 Less Than or Equal LTR <=
12 Greater than LTR >
12 Greater Than or Equal LTR >=
12 in LTR in
12 instanceof LTR instanceof
11 Equality LTR ==
11 Inequality LTR !=
11 Strict Equality LTR ===
11 Strict Inequality LTR !==
10 Bitwise AND LTR &
9 Bitwise XOR LTR ^
8 Bitwise OR LTR |
7 Nullish coalescing operator LTR ??
6 Logical AND LTR &&
5 Logical OR LTR ||
4 Conditional RTL ? :
3 Assignemnt RTL =
3 Assignemnt RTL +=
3 Assignemnt RTL -=
3 Assignemnt RTL **=
3 Assignemnt RTL *=
3 Assignemnt RTL /=
3 Assignemnt RTL %=
3 Assignemnt RTL <<=
3 Assignemnt RTL >>=
3 Assignemnt RTL >>>=
3 Assignemnt RTL &=
3 Assignemnt RTL ^=
3 Assignemnt RTL |=
2 yield RTL yield
2 yield* RTL yield*
1 Comma/Sequence LTR ,

A few notes about the above table:

  1. The Associativity column indicate how this operation will operate, from Left-to-right (LTR) or Right-to-left (RTL).

For more details, read this page.

🎗️ TODO: Should I add a section that describes what each of the operators does? (More than likely, but I don't feel like doing it right now.)

Compound Assignment Operators

Compound assignment operators allow us to use a shorthand to execute some operators. They have a low precedence so they won't execute until all the stuff on the right-hand side is computed.

Shorthand Meaning
x = y x = y
x += y x = x + y
x -= y x = x - y
x **= y x = x ** y
x *= y x = x * y
x /= y x = x / y
x %= y x = x % y
x <<= y x = x << y
x >>= y x = x >> y
x >>>= y x = x >>> y
x &= y x = x & y
x ^= y x = x ^ y
x |= y x = x | y

#Computer_Science