no-null
March 27, 2026 Β· View on GitHub
π Disallow the use of the null literal.
πΌπ« This rule is enabled in the β
recommended config. This rule is disabled in the βοΈ unopinionated config.
π§π‘ This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.
Disallow the use of the null literal, to encourage using undefined instead. You can learn why in https://github.com/sindresorhus/meta/discussions/7
Examples
// β
let foo = null;
// β
let foo;
// β
if (bar == null) {}
// β
if (bar == undefined) {}
// β
const foo = Object.create(null);
// β
if (foo === null) {}
Options
Type: object
checkStrictEquality
Type: boolean
Default: false
Strict equality(===) and strict inequality(!==) is ignored by default.
/* eslint unicorn/no-null: ["error", {"checkStrictEquality": true}] */
// β
if (foo === null) {}
Why
- βIntent to stop using
nullin my JS codeβ. - TypeScript coding guidelines.
- ESLint rule proposal.
- Douglas Crockford on bottom values in JavaScript.