Course contentsShow
← JavaScript
Lesson 307 of 2,7238. Type CoercionFree lesson

Linter Rules for Equality

Understand how ESLint's eqeqeq rule enforces === and when to configure exceptions.

Linter Rules for Equality

You'll learn how linters can automatically enforce strict equality (===) and when you might configure exceptions.

What Are Linter Rules?

Linters like ESLint analyze your code for potential problems before you run it. Think of a linter as a helpful editor who circles questionable choices in red ink—catching issues that won't break your code but might cause bugs later.

The eqeqeq Rule

ESLint's eqeqeq rule specifically targets equality checks. By default, it flags any use of == or != and suggests replacing them with === or !==.

// ESLint will warn about this:
if (value == 5) { }

// ESLint prefers this:
if (value === 5) { }

This rule exists because loose equality's type coercion creates the unpredictable scenarios you've learned about (like 0 == '0' but also 0 == false).

Configuring Exceptions

You can configure eqeqeq with options:

  • "always" (default) - always require ===
  • "smart" - allows == only for safe cases like comparing to null/undefined
  • "allow-null" - permits value == null to check for both null and undefined at once

Some teams use "allow-null" because value == null is a common, intentional pattern that checks both nullish values simultaneously.

Why This Matters

Linter rules transform best practices from "remember to do this" into automatic enforcement. Instead of relying on code review or memory, your editor warns you immediately when you use loose equality.

Key Takeaway: The eqeqeq linter rule automatically enforces strict equality (===), preventing type coercion bugs before they reach production—though you can configure exceptions for specific patterns like nullish checks.