Java Reference
In-Depth Information
operator precedence
Does
1 + 2 * 3 = 1 + (2 * 3) = 7
or does it equal
(1 + 2) * 3 = 9
?
Operator precedence determines the order in which operators are evaluated. For example, the
multiplicative operator (
*
) has a higher precedence than the additive operator (
+
). Therefore, the
correct answer to the previous question is:
1 + (2 * 3)
The following table lists the operator precedence in JavaScript from highest to lowest. The third
column explains whether to read
1+2+3+4
as
((1+2)+3)+4
(left to right) or
1+(2+(3+(4)))
(right to left).
operator type
operators
evaluation order for like eleMents
Member
.
or
[]
Left to right
Create instance
Right to left
new
Function call
Left to right
()
Increment
N/a
++
Decrement
N/a
--
Logical not
Right to left
!
Bitwise not
Right to left
~
Unary +
Right to left
+
Unary
-
Right to left
-
Type of
Right to left
typeof
Void
Right to left
void
Delete
Right to left
delete
Multiplication
Left to right
*
Division
Left to right
/
Modulus
Left to right
%
Addition
Left to right
+
Subtraction
Left to right
-
Bitwise shift
Left to right
<<, >>, >>>
Relational
Left to right
<, <=, >, >=
In
Left to right
in
Instance of
Left to right
instanceof
continues