# logical-assignment-operators

Rule `unicorn/logical-assignment-operators`. Require or disallow logical assignment operator shorthand

- Source: unicorn
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 9.9M weekly downloads of presets that enable it
- Trend: +28.3% last quarter
- Rank: #1033 by reach, #1288 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/logical-assignment-operators` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/logical-assignment-operators.md) |

## Code examples

### Incorrect: the rule reports this

```js
if (!foo) {
  foo = bar;
}
```

```js
if (!object[key]) {
  object[key] = [];
}
```

### Correct: the rule accepts this

```js
foo ||= bar;
```

```js
foo ??= bar;
```

```js
object[key] ||= [];
```

Examples from the ESLint documentation.

## Enable it

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

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/logical-assignment-operators": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [eslint/logical-assignment-operators](https://lintradar.dev/rules/eslint/logical-assignment-operators.md): Require or disallow logical assignment operator shorthand
- [unicorn/consistent-conditional-object-spread](https://lintradar.dev/rules/unicorn/consistent-conditional-object-spread.md): Enforce consistent conditional object spread style.
- [unicorn/name-replacements](https://lintradar.dev/rules/unicorn/name-replacements.md): Enforce replacements for variable, property, and filenames.
- [unicorn/consistent-class-member-order](https://lintradar.dev/rules/unicorn/consistent-class-member-order.md): Enforce consistent class member order.
- [unicorn/no-array-concat-in-loop](https://lintradar.dev/rules/unicorn/no-array-concat-in-loop.md): Disallow array accumulation with `Array#concat()` in loops.
- [unicorn/class-reference-in-static-methods](https://lintradar.dev/rules/unicorn/class-reference-in-static-methods.md): Enforce consistent class references in static methods.

---

Web page: https://lintradar.dev/rules/unicorn/logical-assignment-operators. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
