src/content/docs/linter/rules/no-ternary.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> :::caution This rule is part of the [nursery](/linter/#nursery) group. This means that it is experimental and the behavior can change at any time. ::: ## Summary - Rule available since: `v2.3.8` - Diagnostic Category: [`lint/nursery/noTernary`](/reference/diagnostics#diagnostic-category) - This rule doesn't have a fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`no-ternary`](https://eslint.org/docs/latest/rules/no-ternary){
"linter": {
"rules": {
"nursery": {
"noTernary": "error"
}
}
}
}
Disallow ternary operators.
The ternary operator is used to conditionally assign a value to a variable. Some believe that the use of ternary operators leads to unclear code.
const foo = isBar ? baz : qux;
let foo;
if (isBar) {
foo = baz;
} else {
foo = qux;
}