src/content/docs/linter/rules/no-comma-operator.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/complexity/noCommaOperator`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule doesn't have a fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`no-sequences`](https://eslint.org/docs/latest/rules/no-sequences){
"linter": {
"rules": {
"complexity": {
"noCommaOperator": "error"
}
}
}
}
Disallow comma operator.
The comma operator includes multiple expressions where only one is expected. It evaluates every operand from left to right and returns the value of the last operand. It frequently obscures side effects, and its use is often an accident.
The use of the comma operator in the initialization and update parts of a for is still allowed.
const foo = (doSomething(), 0);
for (; doSomething(), !!test; ) {}
// Use a semicolon instead.
let a, b;
a = 1, b = 2;
for(a = 0, b = 0; (a + b) < 10; a++, b += 2) {}