Operator precedence

Operator precedence determines the order in which operators are evaluated. Operators with higher precedence are evaluated first.
A common example:
3 + 4 * 5 // returns 23
The multiplication operator ("*") has higher precedence than the addition operator ("+") and thus will be evaluated first.

AssociativityEdit

Associativity determines the order in which operators of the same precedence are processed. For example, consider an expression:
a OP b OP c
Left-associativity (left-to-right) means that it is processed as (a OP b) OP c, while right-associativity (right-to-left) means it is interpreted as a OP (b OP c). Assignment operators are right-associative, so you can write:
a = b = 5;
with the expected result that a and b get the value 5. This is because the assignment operator returns the value that it assigned. First, b is set to 5. Then the a is also set to 5, the return value of b = 5, aka right operand of the assignment.

TableEdit

The following table is ordered from highest (20) to lowest (0) precedence.
PrecedenceOperator typeAssociativityIndividual operators
20Groupingn/a( … )
19Member Accessleft-to-right… . …
Computed Member Accessleft-to-right… [ … ]
new (with argument list)n/anew … ( … )
Function Callleft-to-right… ( … )
18new (without argument list)right-to-leftnew …
17Postfix Incrementn/a… ++
Postfix Decrementn/a… --
16Logical NOTright-to-left! …
Bitwise NOTright-to-left~ …
Unary Plusright-to-left+ …
Unary Negationright-to-left- …
Prefix Incrementright-to-left++ …
Prefix Decrementright-to-left-- …
typeofright-to-lefttypeof …
voidright-to-leftvoid …
deleteright-to-leftdelete …
15Exponentiationright-to-left… ** …
14Multiplicationleft-to-right… * …
Divisionleft-to-right… / …
Remainderleft-to-right… % …
13Additionleft-to-right… + …
Subtractionleft-to-right… - …
12Bitwise Left Shiftleft-to-right… << …
Bitwise Right Shiftleft-to-right… >> …
Bitwise Unsigned Right Shiftleft-to-right… >>> …
11Less Thanleft-to-right… < …
Less Than Or Equalleft-to-right… <= …
Greater Thanleft-to-right… > …
Greater Than Or Equalleft-to-right… >= …
inleft-to-right… in …
instanceofleft-to-right… instanceof …
10Equalityleft-to-right… == …
Inequalityleft-to-right… != …
Strict Equalityleft-to-right… === …
Strict Inequalityleft-to-right… !== …
9Bitwise ANDleft-to-right… & …
8Bitwise XORleft-to-right… ^ …
7Bitwise ORleft-to-right… | …
6Logical ANDleft-to-right… && …
5Logical ORleft-to-right… || …
4Conditionalright-to-left… ? … : …
3Assignmentright-to-left… = …
… += …
… -= …
… **= …
… *= …
… /= …
… %= …
… <<= …
… >>= …
… >>>= …
… &= …
… ^= …
… |= …
2yieldright-to-leftyield …
yield*right-to-leftyield* …
1Spreadn/a... …
0Comma / Sequenceleft-to-right… , …

Comments

Popular posts from this blog

Install Brackets Editor In Ubuntu 14.04 And Linux Mint 17 Via PPA