Standard Library
The Standard Library
contains utilities that are functionally broken but remain for legacy reasons.
29.1 Use
Number.isNaN
instead of globalisNaN
.
eslint:no-restricted-globals
Why? The global
isNaN
coerces non-numbers to numbers, returning true for anything that coerces to NaN.
If this behavior is desired, make it explicit.// bad
isNaN('1.2'); // false
isNaN('1.2.3'); // true
// good
Number.isNaN('1.2.3'); // false
Number.isNaN(Number('1.2.3')); // true
29.2 Use
Number.isFinite
instead of globalisFinite
.
eslint:no-restricted-globals
Why? The global
isFinite
coerces non-numbers to numbers, returning true for anything that coerces to a finite number.
If this behavior is desired, make it explicit.// bad
isFinite('2e3'); // true
// good
Number.isFinite('2e3'); // false
Number.isFinite(parseInt('2e3', 10)); // true