equalityOperators
Enforces consistent use of strict equality operators (=== and !==) over loose equality operators (== and !=) for non-nullish comparisons.
✅ This rule is included in the tslogicalandlogicalStrictpresets.
The loose equality operators (== and !=) perform type coercion before comparison, which can lead to surprising and confusing behavior.
Strict equality operators (=== and !==) compare both value and type without coercion, making comparisons more predictable.
Therefore, it is almost always preferable to use the strict equality operators.
Examples
Section titled “Examples”if (value == 5) { doSomething();}if (name != "admin") { checkPermissions();}if (value === 5) { doSomething();}if (name !== "admin") { checkPermissions();}Options
Section titled “Options”This rule has no options.
When Not To Use It
Section titled “When Not To Use It”If your codebase has specific requirements for using loose equality operators in certain niche contexts, you may want to use a disable comment for those specific cases. For example, if you intentionally deal with numbers and strings interchangeably, and are accustomed to directly comparing them, this rule you might not be for you.
Related Rules
Section titled “Related Rules”- nullishCheckStyle - Enforces consistent equality operator usage for nullish comparisons
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noDoubleEquals - Deno:
eqeqeq - ESLint:
eqeqeq - Oxlint:
eslint/eqeqeq