# prefer-math-abs

Rule `unicorn/prefer-math-abs`. Prefer `Math.abs()` over manual absolute value expressions and symmetric range checks.

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

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/prefer-math-abs` | no | suggestion | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/prefer-math-abs.md) |
| Biome | `nursery/useMathAbs` | yes | unsafe | group nursery, since 2.6.3 | [docs](https://biomejs.dev/linter/rules/use-math-abs/) |

## Code examples

### Incorrect: the rule reports this

```js
const absolute = value < 0 ? -value : value;
```

```js
const absolute = value <= 0 ? 0 - value : value;
```

```js
const absolute = value > 0 ? value : -value;
```

### Correct: the rule accepts this

```js
const absolute = Math.abs(value);
```

```js
if (Math.abs(number) > MAXIMUM) {
}
```

Examples from the ESLint documentation.

## Enable it

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

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

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/prefer-math-abs": "error",
    },
  },
];
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "useMathAbs": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Biome recommended](https://lintradar.dev/presets/biome-recommended.md) | Biome | `@biomejs/biome` | 491 | 28.5M | +106.8% |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [Unicorn unopinionated](https://lintradar.dev/presets/unicorn-unopinionated.md) | ESLint | `eslint-plugin-unicorn` | 236 | 9.5M | +30.3% |
| [Ultracite for Biome](https://lintradar.dev/presets/ultracite-biome.md) | Biome | `ultracite` | 616 | 2.1M | +151.7% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/prefer-flat-math-min-max](https://lintradar.dev/rules/unicorn/prefer-flat-math-min-max.md): Prefer flat `Math.min()` and `Math.max()` calls over nested calls.
- [unicorn/prefer-math-constants](https://lintradar.dev/rules/unicorn/prefer-math-constants.md): Prefer `Math` constants over their approximate numeric values.
- [unicorn/prefer-boolean-return](https://lintradar.dev/rules/unicorn/prefer-boolean-return.md): Prefer directly returning boolean expressions over `if` statements.
- [unicorn/prefer-unary-minus](https://lintradar.dev/rules/unicorn/prefer-unary-minus.md): Prefer the unary minus operator over multiplying or dividing by `-1`.
- [unicorn/prefer-block-statement-over-iife](https://lintradar.dev/rules/unicorn/prefer-block-statement-over-iife.md): Prefer block statements over IIFEs used only for scoping.
- [unicorn/prefer-while-loop-condition](https://lintradar.dev/rules/unicorn/prefer-while-loop-condition.md): Prefer putting the condition in the while statement.

---

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