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

178
Visualizações
Will a zero number return true using IsNaN?

I'm having a little bit of an issue with IsNaN. When the number 'Zero' is passed to it, it fires off as true, rather than false as expected.

I'm parsing a number from a string, converting it to a float using parseFloat:

let val = parseFloat(value.substring(value.indexOf(";")+1, value.lastIndexOf(";")));

then storing 'val' in an array This works perfectly fine and works as expected, however when I later check to make sure it is in fact a number with IsNAN, using this line of code: let DispVal = (isNaN(val) || val== "")? "Value: Loading" : "Value:" + val;

This works perfectly fine, unless the number is zero. If the number is zero it uses it's set to 'Value: Loading'

I had thought this may be due to '0' also being considered false, but the way the documentation for isNaN has me doubting that somewhat

Is there something I'm doing wrong here, or some where our data might be getting mangled

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In js the result of the expression 0 == "" is (surprisingly) true.

This is because "" is being coerced into a number and Number("") is 0

So when val is equal to 0 you get your loading state

about 4 years ago · Juan Pablo Isaza 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