Conversion

A BR loosing a lottery as it used octal base





Ever wrote a logic that used parseInt() method? Be careful about second parameter in the function call. It signifies the base for the conversion. If not explicitly mentioned parseInt(), it could be inferred based on the string value. But, it may not always be decimal.

I once wrote an integration script that completely relied on number conversion from string to integer. I did not explicitly pass the second radix parameter, although the functionality worked for like an year, it suddenly broke in Production one day. After spending a sleepless night and questioning my ability to be a developer multiple times, I finally realised my mistake. Unless you are into sleepless nights and self doubts, don't repeat such a mistake.

Don't break hearts in the GlideWorld, always pass the radix argument if using parseInt() method.









Creative Commons License

Comments