AJAX - The Complete Reference

(avery) #1

PART IV


Appendix A: JavaScript Quick Reference 575


Statements and Blocks


JavaScript statements are terminated either with a semicolon or an implied semicolon as
indicated by a return character. Thus:

var x = 5;
var y = 10;

and:

var x = 5
var y = 10

are equivalent. However, because of whitespace reflow, the second is clearly more
dangerous as it is sensitive to formatting.
We can group statements together in JavaScript using a block as indicated by enclosing
them in curly braces:

{
statements
}

where statements is composed of zero or more valid JavaScript statements. Statements can
always be grouped like this, as the body of a loop or function, or directly in the script,
although a block has only its own local scope for functions. However, we saw earlier, under
JavaScript 1.7 it is possible to create local bindings using a let statement.

Precedence Associativity Operator Operator Meanings

Left ==, !=, ===, !=== Equality, inequality, equality with
type checking, inequality with type
checking
Left & Bitwise AND

Left ^ Bitwise XOR
Left | Bitwise OR
Left && Logical AND

Left || Logical OR
Right? : Conditional
Right = Assignment
Right *=, /=, %=, +=, –=,
<<=, >>=, >>>=, &=,
^=, |=

Operation and self-assignment

Lowest Left , Multiple evaluation

TABLE A-18 Precedence and Associativity of JavaScript Operators (continued)
Free download pdf