Name

, — NN 2 IE J1 ECMA 1

Synopsis

The comma operator. This operator can delimit expressions in the same line of script. It can be used in a number of ways. For example, to declare multiple variables, the syntax would be:

var varName1, varName2, ... varNameN

Multiple script statements may also be joined together on the same line. Therefore, the following script line:

alert("Howdy"),alert("Doody")

presents two alert dialog boxes in sequence (the second one appears after the first is dismissed by the user). Another application is in for loops when you wish to involve two (or more) variables in the loop:

for (var i = 0, var j = 2; i < 20; i++, j++) {
    ...
}

Example

var isNav, isIE

Get Dynamic HTML: The Definitive Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.