# no-undefined-argument

Rule `sonarjs/no-undefined-argument`. "undefined" should not be passed as the value of optional parameters

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: yes
- Autofix: yes, in at least one linter
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1321 by reach, #622 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/no-undefined-argument` | yes | suggestion | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-4623/) |

## Code examples

### Incorrect: the rule reports this

```js
function foo(x: number, y: string = "default", z?: number) {
  // ...
}

foo(42, undefined); // Noncompliant
foo(42, undefined, undefined); // Noncompliant
foo(42, undefined, 5); // OK, there is no other way to force default value for second parameter
```

### Correct: the rule accepts this

```js
function foo(x: number, y: string = "default", z?: number) {
  // ...
}

foo(42);
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/no-undefined-argument": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/no-try-promise](https://lintradar.dev/rules/sonarjs/no-try-promise.md): Promise rejections should not be caught by "try" blocks
- [sonarjs/no-unenclosed-multiline-block](https://lintradar.dev/rules/sonarjs/no-unenclosed-multiline-block.md): Multiline blocks should be enclosed in curly braces
- [sonarjs/no-trivial-assertions](https://lintradar.dev/rules/sonarjs/no-trivial-assertions.md): Assertions should not be trivially true
- [sonarjs/no-uniq-key](https://lintradar.dev/rules/sonarjs/no-uniq-key.md): JSX list components keys should match up between renders
- [sonarjs/no-table-as-layout](https://lintradar.dev/rules/sonarjs/no-table-as-layout.md): HTML "<table>" should not be used for layout purposes
- [sonarjs/no-unthrown-error](https://lintradar.dev/rules/sonarjs/no-unthrown-error.md): Errors should not be created without being thrown

---

Web page: https://lintradar.dev/rules/sonarjs/no-undefined-argument. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
