Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!