Javascript Reference
Categories: Operators

javascript Operators ,

@March 15, 2008, 1:22 a.m.
, Firefox/Netscape/NN 2 IE 3 ECMA 1  

  

The comma operator (with or without optional white space following it) 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 isCSS, isIEMac;

Powered by Linode.