src/content/docs/linter/rules/no-useless-undefined.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v2.0.0` - Diagnostic Category: [`lint/complexity/noUselessUndefined`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has a [**safe**](/linter/#safe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`unicorn/no-useless-undefined`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-useless-undefined.md){
"linter": {
"rules": {
"complexity": {
"noUselessUndefined": "error"
}
}
}
}
Disallow the use of useless undefined.
undefined is the default value for new variables, parameters, return statements, etc., so specifying it doesn't make any difference.
let foo = undefined;
const {foo = undefined} = bar;
function foo() {
return undefined;
}
function* foo() {
yield undefined;
}
function foo(bar = undefined) {}
function foo({bar = undefined}) {}
let foo;
const {foo} = bar;
function foo() {
return;
}
function* foo() {
yield;
}
function foo(bar) {}
function foo({bar}) {}
foo();