src/content/docs/linter/rules/no-constant-condition.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/correctness/noConstantCondition`](/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 [**error**](/reference/diagnostics#error). - Sources: - Same as [`no-constant-condition`](https://eslint.org/docs/latest/rules/no-constant-condition){
"linter": {
"rules": {
"correctness": {
"noConstantCondition": "error"
}
}
}
}
Disallow constant expressions in conditions
if (false) {
doSomethingUnfinished();
}
if (Boolean(1)) {
doSomethingAlways();
}
if (undefined) {
doSomethingUnfinished();
}
for (;-2;) {
doSomethingForever();
}
while (typeof x) {
doSomethingForever();
}
var result = 0 ? a : b;
if (x === 0) {
doSomething();
}
for (;;) {
doSomethingForever();
}
while (typeof x === "undefined") {
doSomething();
}
do {
doSomething();
} while (x);
var result = x !== 0 ? a : b;
// Exception
while (true) {
if (x) { break; }
x = f();
}