574 Part IV: Appendixes
- If two strings are identical up to the nth (possibly 0th) character then the (n + 1)st
character is examined. For example, the third character of “abc” and “abd” would
be examined if they were to be compared. - If the numeric value of the character code under examination in the first string is
less than that of the character in the second string, the first string is “less than”
second. The relation “1” < “9” < “A” < “Z” < “a” < “z” is often helpful for
remembering which characters come “less” than others.
Operator Precedence and Associativity
JavaScript assigns a precedence and associativity to each operator so that expressions will
be well-defined, that is, the same expression will always evaluate to the same value.
Operators with higher precedence evaluate before operators with lower precedence.
Associativity determines the order in which identical operators evaluate. We use the symbol
⊗ to specify an arbitrary operator, so given the expression:
a ⊗ b ⊗ c
a left-associative operator would evaluate:
(a ⊗ b) ⊗ c
while a right-associative operator would evaluate
a ⊗ (b ⊗ c)
Table A-18 summarizes operator precedence and associativity in JavaScript.
Precedence Associativity Operator Operator Meanings
Highest Left ., [ ], () Object property access, array or
object property access, parenthesized
expression
Right ++, ––, –, ~, !,
delete, new, typeof,
void
Pre/post increment, pre/post
decrement, arithmetic negation,
bitwise negation, logical negation,
removal of a property, object creation,
getting data type, undefine or dispose
of a value
Left *, /, % Multiplication, division, modulus
Left +, – Addition (arithmetic) and
concatenation (string), subtraction
Left <<, >>, >>> Bitwise left shift, bitwise right shift,
bitwise right shift with zero fill
Left <, <=, >, >=, in,
instanceof
Less than, less than or equal to,
greater than, greater than or equal
to, object has property, object is an
instance of
TABLE A-18 Precedence and Associativity of JavaScript Operators