Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

87
Visualizações
ESLint Unexpected use of isNaN

I'm trying to use the isNaN global function inside an arrow function in a Node.js module but I'm getting this error:

[eslint] Unexpected use of 'isNaN'. (no-restricted-globals)

This is my code:

const isNumber = value => !isNaN(parseFloat(value));

module.exports = {
  isNumber,
};

Any idea on what am I doing wrong?

PS: I'm using the AirBnB style guide.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

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.

// bad
isNaN('1.2'); // false
isNaN('1.2.3'); // true

// good
Number.isNaN('1.2.3'); // false
Number.isNaN(Number('1.2.3')); // true
over 4 years ago · Santiago Trujillo Relatório

0

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

over 4 years ago · Santiago Trujillo Relatório

0

@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
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda