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

118
Vistas
Very strange behaviour of parseInt and map

Take a look at this experiment conducted on jsconsole.com

> parseInt("00")
0
> ["00"].map(parseInt)
Array (1)[ 0 ]
> ["123", "00"].map(parseInt)
Array (2)[ 123,NaN ]
> ["00", "123"].map(parseInt)
Array (2)[ 0,NaN ]

I've stumbled upon this by trying to do some date-time parsing. The problem seemed to be the fact that I didn't specify which integer base I want. Using parseInt(x, 10) solves my problem but could someone explain to me how ["00"].map(parseInt) and ["123", "00"].map(parseInt) could possibly differ for the value of "00"? I might be missing something extremely obvious here, but if I'm not this would mean that there's something wrong with Array.prototype.map or parseInt or both.

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It has to do with the extra parameters map adds to the method call. Try the following snippet to get the correct results. This prevents parseInt from receiving them.

console.log(["123", "00"].map(it=>parseInt(it)))

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