Skip to content
← Back to rules

unicorn/no-useless-undefined Pedantic

🛠️ An auto-fix is available for this rule.

What it does

Prevents usage of undefined in cases where it would be useless.

WARNING

This rule can conflict with the default behaviors of the eslint/array-callback-return and eslint/getter-return rules. For both rules, you can set the allowImplicit option to avoid conflicts.

Why is this bad?

undefined is the default value for new variables, parameters, return statements, etc, so specifying undefined in these cases is pointless.

Examples

Examples of incorrect code for this rule:

javascript
let foo = undefined;
const noop = () => undefined;

Examples of correct code for this rule:

javascript
let foo;
const noop = () => {};

Configuration

This rule accepts a configuration object with the following properties:

checkArguments

type: boolean

default: true

Whether to check for useless undefined in function call arguments.

checkArrowFunctionBody

type: boolean

default: true

Whether to check for useless undefined in arrow function bodies.

How to use

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "unicorn/no-useless-undefined": "error"
  }
}
bash
oxlint --deny unicorn/no-useless-undefined

References