lint warning: parseInt missing radix parameter [duplicate]

坚强是说给别人听的谎言 提交于 2019-12-10 01:45:26

问题


I have the following code that gives the warning described in the title:

          year: parseInt(dateParts[0]),
               ......................^

Any help is much appreciated


回答1:


See the manual for parseInt; it takes 2 arguments. The second one tells it which number base you want to use. This is almost always going to be 10 (decimal).

parseInt(dateParts[0],10)

If you don't specify it, then it will be inferred from the data.

If radix is undefined or 0 (or absent), JavaScript assumes the following:

If the input string begins with "0x" or "0X", radix is 16 (hexadecimal) and the remainder of the string is parsed.

If the input string begins with "0", radix is eight (octal) or 10 (decimal). Exactly which radix is chosen is implementation-dependent. ECMAScript 5 specifies that 10 (decimal) is used, but not all browsers support this yet. For this reason always specify a radix when using parseInt.

If the input string begins with any other value, the radix is 10 (decimal).



来源:https://stackoverflow.com/questions/17681843/lint-warning-parseint-missing-radix-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!