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

>> "If the radix provided is falsy, then by default, radix is set to 10."

The official docs for parseInt says this:

>> An integer between 2 and 36 that represents the radix (the base in mathematical numeral systems) of the string. Be careful — this does not default to 10. [1]

I just found it confusing whether the author meant the default value is 10, or if a falsy parameter (not undefined) turns out to be 10.

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...



So looking at the rest of the documentation, the parameter not being set causes the default radix to be 10 unless the number starts with 0 or 0x, in which case they radix is 8 or 16 respectively. Though newer versions of JS no longer support the octal syntax (it likely just caused bugs for people who had initial zeros in their strings sometimes)

parseInt("0x10") == 16 parseInt("0x10", 10) == 0


Agreed - if you read the description section in the Mozilla docs, there is no mention of falsy. He should eliminate that section.




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

Search: