Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

or just this:

  ['10', '10', '10'].map(val => parseInt(val))
Leading zeroes can often be considered invalid input, and you may be able to safely assume that it has been dealt with already.

Also the parens around a single argument of an arrow function are a superstitious thing suggested by some well-known react developer a while back, I think.



I have my linting setup to force a base on `parseInt`, for the extra characters I do feel it's worth it for the safety.

The extra parentheses is just habit from Prettier formatting :)



Also, no reason to write extra characters just to prevent people from using hexadecimal, it's often convenient and it comes for free!


Octal is sneakier than hexadecimal, especially if the values are from user input.

['07', '08', '09'].map(val => parseInt(val)) // => [7, 0, 0]



Plus there's this if you really want to support old browsers: https://github.com/zloirock/core-js/blob/ce52fdc735c5c809c9e...


was

['07', '08', '09'].map(val => parseInt(val)) // => [7, 8, 9]




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: