unicorn/prefer-number-properties Restriction
What it does
Disallows use of parseInt()
, parseFloat()
, isNan()
, isFinite()
, Nan
, Infinity
and -Infinity
as global variables.
Why is this bad?
ECMAScript 2015 moved globals onto the Number
constructor for consistency and to slightly improve them. This rule enforces their usage to limit the usage of globals:
Number.parseInt()
overparseInt()
Number.parseFloat()
overparseFloat()
Number.isNaN()
overisNaN()
(they have slightly different behavior)Number.isFinite()
overisFinite()
(they have slightly different behavior)Number.NaN
overNaN
Number.POSITIVE_INFINITY
overInfinity
Number.NEGATIVE_INFINITY
over-Infinity
Examples
Examples of incorrect code for this rule:
javascript
const foo = parseInt("10", 2);
const bar = parseFloat("10.5");
Examples of correct code for this rule:
javascript
const foo = Number.parseInt("10", 2);
const bar = Number.parseFloat("10.5");