Skip to content

equalityOperators

Enforces consistent use of strict equality operators (=== and !==) over loose equality operators (== and !=) for non-nullish comparisons.

✅ This rule is included in the ts logical and logicalStrict presets.

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.

if (value == 5) {
doSomething();
}
if (name != "admin") {
checkPermissions();
}

This rule has no options.

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.

  • nullishCheckStyle - Enforces consistent equality operator usage for nullish comparisons
Made with ❤️‍🔥 around the world by the Flint team and contributors.