src/content/docs/linter/rules/no-double-equals.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/suspicious/noDoubleEquals`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). - Sources: - Same as [`eqeqeq`](https://eslint.org/docs/latest/rules/eqeqeq){
"linter": {
"rules": {
"suspicious": {
"noDoubleEquals": "error"
}
}
}
}
Require the use of === and !==.
It is generally bad practice to use == for comparison instead of
===. Double operators will trigger implicit type coercion
and are thus not preferred. Using strict equality operators is almost
always best practice.
For ergonomic reasons, this rule makes by default an exception for == null for
comparing to both null and undefined.
foo == bar
foo == null
foo != null
null == foo
null != foo
The rule provides the option described below.
{
"//":"...",
"options": {
"ignoreNull": true
}
}
When this option is set to true, an exception will be made for checking against null,
as relying on the double equals operator to compare with null is frequently used to check
equality with either null or undefined.
When the option is set to false, all double equal operators will be forbidden without
exceptions.
Default: true