# unicorn/prefer-number-properties

> Require `Number.isNaN`, `Number.parseInt` and the like instead of the globals

The global `isNaN` and `isFinite` convert their argument to a number first, so `isNaN("abc")` is `true` and `isFinite("1")` is `true`. `Number.isNaN` and `Number.isFinite` don't convert, so they're `false` for anything that isn't a number.

`Number.parseInt`, `Number.parseFloat` and `Number.NaN` are the same as the globals. The rule reports the globals so that everything about numbers is written the same way.

`--fix` rewrites `parseInt`, `parseFloat`, `NaN` and `Infinity`. It doesn't touch `isNaN` and `isFinite`, because the result can change. `--fix-dangerously` rewrites those too.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"unicorn/prefer-number-properties" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"unicorn/prefer-number-properties" = ["error", {
  checkInfinity = false,
  checkNaN = true,
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 4} */}
```js
const width = parseInt(style.width, 10);

if (isNaN(width)) {
  reset(NaN);
}

const isValid = window.isFinite(width);
```

Not reported:

{/* good */}
```js
const width = Number.parseInt(style.width, 10);

if (Number.isNaN(width)) {
  reset(Number.NaN);
}

const isValid = Number.isFinite(width);
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `checkInfinity` | `false` | Also report `Infinity` and `-Infinity`. Write `Number.POSITIVE_INFINITY` and `Number.NEGATIVE_INFINITY`. |
| `checkNaN` | `true` | Report `NaN`. |

`Infinity` is only reported with `checkInfinity`:

{/* good */}
```js
let lowest = Infinity;
```

{/* bad {"options": [{"checkInfinity": true}]} */}
```js
let lowest = Infinity;
```

With `checkNaN: false`, `NaN` is allowed:

{/* good {"options": [{"checkNaN": false}]} */}
```js
const missing = NaN;
```
