In every language, evaluation of an expression is done based on a predefined order of precedence which helps the language engine to determine which part of the expression will be evaluated first, which will second, and so on.
Operator precedence in JavaScript
Operator | Operation | Order of Precedence | Order of Evaluation |
++ | Increment | 1 | R -> L |
— | Decrement | 1 | R -> L |
— | Negation | 1 | R -> L |
! | NOT | 1 | R -> L |
*, /, | Multiplication, division, modulus | 2 | L -> R |
+, — | Addition, subtraction | 3 | L -> R |
+ | Concatenation | 3 | L -> R |
<, <= | Less than, less than, or equal | 4 | L -> R |
>, >= | Greater than, greater than, or equal | 4 | L -> R |
== | Equal | 5 | L -> R |
!= | Not equal | 5 | L -> R |
=== | Identity | 5 | L -> R |
!== | Non-identity | 5 | L -> R |
&& | AND | 6 | L -> R |
|| | OR | 6 | L -> R |
?: | Ternary | 7 | R -> L |
= | Assignment | 8 | R -> L |
+=, -=, and so on. | Arithmetic assignment | 8 | R -> L |