eqeqeq
It’s considered good practice to use type-safe equality operators=== and !== instead of == and !=.
Rule Type: Suggestion
Fixable: Yes (in some cases)
Fixable: Yes (in some cases)
Why This Rule Exists
The== and != operators do type coercion following obscure rules, leading to unexpected results:
=== and !== avoids these surprises by not performing type coercion.
Rule Details
This rule enforces use of type-safe equality operators.Examples
Incorrect Code
Correct Code
Options
"always" (default)
Enforce === and !== in every situation.
Incorrect:
null option
Customize how the rule treats null comparisons:
"always"(default) - Always use===or!=="never"- Never use===or!==withnull"ignore"- Don’t checknullcomparisons
"smart"
Allows == and != in these cases:
- Comparing two literal values
- Evaluating
typeof - Comparing against
null
Common Patterns
null/undefined Checks
Type Coercion Surprises
Safe Type Coercion
Configuration Examples
Auto-fixing
This rule can auto-fix when:- One operand is a
typeofexpression - Both operands are literals with the same type