Mohamed Lamine Allal
1 min readAug 7, 2019

[‘1’, ‘2’, ‘3’].map(parseInt)> Array(3) [ 1, NaN, NaN ]  // why!!![‘1’, ‘2’, ‘3’].map(a => parseInt(a))> Array(3) [ 1, 2, 3 ]

WHY !!!!!!!!!!!!!!

It’s stupid but a thing

- The second param of parseInt is radix
- The second param of map callback is index
=> so index is screwing it

++> parseInt is executed this way
Parseint(num, index, array) completely screwed

Simply put we can’t use directly parseInt.

Use the arrow function notation num => parseInt(num) and it’s more explicit. Better then making a function parseInt10() for that.

A good lesson: always care about all the parameters

Mohamed Lamine Allal
Mohamed Lamine Allal

Written by Mohamed Lamine Allal

Developper, Entrepreneur, CTO, Writer! A magic chaser! And A passionate thinker! Obsessed with Performance! And magic for life! And deep thinking!

No responses yet