ESLint Unexpected use of isNaN ESLint Unexpected use of isNaN javascript javascript

ESLint Unexpected use of isNaN


As the documentation suggests, use Number.isNaN.

const isNumber = value => !Number.isNaN(Number(value));

Quoting Airbnb's documentation:

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.

// badisNaN('1.2'); // falseisNaN('1.2.3'); // true// goodNumber.isNaN('1.2.3'); // falseNumber.isNaN(Number('1.2.3')); // true


FYI, this will not work for IE.Check here at browser compatibility.


@Andy Gaskell isNumber('1.2.3') return true, you might want to edit your answer and use Number() in place of parseFloat()

    const isEmpty = value => typeof value === 'undefined' || value === null || value === false;    const isNumeric = value => !isEmpty(value) && !Number.isNaN(Number(value));
  console.log(isNumeric('5')); // true  console.log(isNumeric('-5')); // true  console.log(isNumeric('5.5')); // true  console.log(isNumeric('5.5.5')); // false  console.log(isNumeric(null)); // false  console.log(isNumeric(undefined)); // false