Main Page

Comma operator

var iNum = 10;
iNum += 10;
Compound assignment operators exist for each of the major mathematical operations and a few others
as well:
Multiply/Assign (
Divide/Assign (
Modulus/Assign (
Add/Assign (
Subtract/Assign (
Left Shift/Assign (
Signed Right Shift/Assign (
Unsigned Right Shift/Assign (
Comma operator
The comma operator allows execution of more than one operation in a single statement. Example:
var iNum1=1, iNum2=2, iNum3=3;
Most often, the comma operator is used in the declaration of variables.
ECMA-262 describes several
for ECMAScript. Essentially, statements define most of the syn-
tax of ECMAScript and, typically, use one or more keywords to accomplish a given task. Statements can
be simple, such as telling a function to exit, or complicated, such as specifying a number of commands to
be executed repeatedly. This section introduces all the standard ECMAScript statements.
The if statement
One of the most frequently used statements in ECMAScript (and indeed, in many languages), is the
statement. The
statement has the following syntax:
if (
The condition can be any expression; it doesn’t even have to evaluate to an actual Boolean value.
ECMAScript converts it to a Boolean for you. If the condition evaluates to
, statement1 is executed;
if the condition evaluates to
, statement2 is executed. Each of the statements can be either a single
line or a code block (a group of code lines enclosed within braces). For example:
ECMAScript Basics
05_579088 ch02.qxd 3/28/05 11:35 AM Page 53

JavaScript EditorFree JavaScript Editor     Ajax Editor