no-useless-undefined

March 27, 2026 ยท View on GitHub

๐Ÿ“ Disallow useless undefined.

๐Ÿ’ผ This rule is enabled in the following configs: โœ… recommended, โ˜‘๏ธ unopinionated.

๐Ÿ”ง This rule is automatically fixable by the --fix CLI option.

undefined is the default value for new variables, parameters, return statements, etcโ€ฆ so specifying it doesn't make any difference.

Where passing undefined as argument is required is due to bad TypeScript types in functions, in which case you can use checkArguments: false option.

Using undefined as arrow function body sometimes make the purpose more explicit. You can use the checkArrowFunctionBody: false option to allow this.

Examples

// โŒ
let foo = undefined;

// โœ…
let foo;
// โŒ
const {foo = undefined} = bar;

// โœ…
const {foo} = bar;
// โŒ
const noop = () => undefined;

// โœ…
const noop = () => {};
// โŒ
function foo() {
	return undefined;
}

// โœ…
function foo() {
	return;
}
// โŒ
function* foo() {
	yield undefined;
}

// โœ…
function* foo() {
	yield;
}
// โŒ
function foo(bar = undefined) {
}

// โœ…
function foo(bar) {
}
// โŒ
function foo({bar = undefined}) {
}

// โœ…
function foo({bar}) {
}
// โŒ
foo(undefined);

// โœ…
foo();

Options

Type: object

checkArguments

Type: boolean
Default: true

Disallow the use of undefined at the end of function call arguments. Pass checkArguments: false to disable checking them.

// โŒ
/* eslint unicorn/no-useless-undefined: ["error", {"checkArguments": true}] */
foo(bar, baz, undefined);
// โœ…
/* eslint unicorn/no-useless-undefined: ["error", {"checkArguments": false}] */
foo(bar, baz, undefined);

checkArrowFunctionBody

Type: boolean
Default: true

Disallow the use of undefined as arrow function body. Pass checkArrowFunctionBody: false to disable checking them.

/* eslint unicorn/no-useless-undefined: ["error", {"checkArrowFunctionBody": true}] */
// โŒ
const foo = () => undefined;
/* eslint unicorn/no-useless-undefined: ["error", {"checkArrowFunctionBody": false}] */
// โœ…
const foo = () => undefined;

Conflict with ESLint array-callback-return and getter-return rules

We recommend setting allowImplicit option to true for these ESLint rules:

{
	"rules": {
		"array-callback-return": [
			"error",
			{
				"allowImplicit": true
			}
		],
		"getter-return": [
			"error",
			{
				"allowImplicit": true
			}
		]
	}
}