Standard Library

The Standard Library
contains utilities that are functionally broken but remain for legacy reasons.

  • 29.1 Use Number.isNaN instead of global isNaN.
    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.

    1. // bad
    2. isNaN('1.2'); // false
    3. isNaN('1.2.3'); // true
    4. // good
    5. Number.isNaN('1.2.3'); // false
    6. Number.isNaN(Number('1.2.3')); // true

  • 29.2 Use Number.isFinite instead of global isFinite.
    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.

    1. // bad
    2. isFinite('2e3'); // true
    3. // good
    4. Number.isFinite('2e3'); // false
    5. Number.isFinite(parseInt('2e3', 10)); // true