Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda