Skip to main content

eqeqeq

It’s considered good practice to use type-safe equality operators === and !== instead of == and !=.
Rule Type: Suggestion
Fixable: Yes (in some cases)

Why This Rule Exists

The == and != operators do type coercion following obscure rules, leading to unexpected results:
Using === 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:
Correct:

null option

Customize how the rule treats null comparisons:
  • "always" (default) - Always use === or !==
  • "never" - Never use === or !== with null
  • "ignore" - Don’t check null comparisons

"smart"

Allows == and != in these cases:
  • Comparing two literal values
  • Evaluating typeof
  • Comparing against null
Incorrect:
Correct:

Common Patterns

null/undefined Checks

The one useful case for == is checking for null OR undefined.

Type Coercion Surprises

These comparisons with == are all true, but probably not what you want!

Safe Type Coercion

Configuration Examples

Auto-fixing

This rule can auto-fix when:
  • One operand is a typeof expression
  • Both operands are literals with the same type

When Not to Use It

Disable if you don’t want to enforce a style for equality operators. However, this is generally not recommended - the type-safe operators prevent many bugs.

Migration Tips

Finding Issues

Common Fixes