Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sindresorhus/eslint-plugin-unicorn/llms.txt

Use this file to discover all available pages before exploring further.

JavaScript has two bottom values β€” null and undefined β€” which creates unnecessary complexity. Using undefined exclusively keeps the language model simpler: uninitialized variables, missing object properties, and absent function arguments are all naturally undefined. This rule disallows the null literal and encourages undefined as the single bottom value.
Recommendedβœ… recommended
FixableπŸ”§ Auto-fixable
SuggestionsπŸ’‘ Has suggestions
// Assigning null to a variable
let foo = null;

// Loose equality check against null
if (bar == null) {}

Autofix and suggestions

The rule’s fix behavior depends on context:
  • Loose equality (== null, != null) β€” automatically replaced with undefined.
  • return null β€” suggests either removing null (making the return implicit) or replacing it with undefined.
  • let foo = null β€” suggests either removing the initializer entirely or replacing it with undefined.
  • All other cases β€” suggests replacing null with undefined.

Configuration options

checkStrictEquality

Type: boolean
Default: false
By default, strict equality checks (=== null, !== null) are ignored, since they are a common and intentional pattern for detecting null specifically. Set to true to report those as well.
/* eslint unicorn/no-null: ["error", { "checkStrictEquality": true }] */

// Fail β€” strict equality against null is now reported
if (foo === null) {}

Automatic exceptions

The following patterns are always allowed regardless of configuration:
PatternReason
Object.create(null)Creates a prototype-less object β€” a well-established pattern
useRef(null) / React.useRef(null)React ref initialization requires null
node.insertBefore(child, null)DOM API uses null as a sentinel to append at the end
This rule aligns with the TypeScript coding guidelines, which recommend using undefined and avoiding null.

Build docs developers (and LLMs) love