JavaScript , Comma Operator
The comma operator evaluates several expressions from left to right and returns the value of the last one.
Description
The comma operator evaluates each of its operands from left to right and returns the value of the last. It has the lowest precedence of any operator. Its main legitimate use is updating several variables in a for loop's header. Commas in argument lists, array literals and variable declarations are separators, not this operator.
In variable declarations such as let a = 1, b = 2, the commas are part of the declaration syntax, not the comma operator, and the same is true for commas in function arguments, array literals and object literals. Because the operator has the lowest precedence, you need parentheses to use it in most other places, as in const x = (a++, b).
Outside the for loop header, the comma operator mostly appears in minified code, where it squeezes several expressions into one. In hand-written code, separate statements are clearer, and linters often flag the comma operator with rules like ESLint's no-sequences.
Properties
- Operator
,- Category
- Other
- Precedence
- 1 (1 is lowest, 18 is highest)
- Associativity
- left-to-right
Syntax
expr1, expr2, expr3Example
Browser Support
The following information will show you the current browser support for the , operator. Hover over a browser icon to see the version that first introduced support for this operator.
Desktop





Tablets & Mobile





