棉绒警告:parseInt缺少基数参数 [英] lint warning: parseInt missing radix parameter

查看:65
本文介绍了棉绒警告:parseInt缺少基数参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码给出标题中描述的警告:

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

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

非常感谢您的帮助

推荐答案

请参见 parseInt 的手册;它需要2个参数.第二个告诉您要使用的数字基数.几乎总是10(十进制).

parseInt(dateParts[0],10)

如果未指定,则将从数据中推断出来.

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

如果未定义基数或0(或不存在),则JavaScript假定以下内容:

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

如果输入字符串以"0x"或"0X"开头,则基数为16 (十六进制),然后解析字符串的其余部分.

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

如果输入字符串以"0"开头,则基数为八(八进制)或10 (十进制).究竟选择哪个基数取决于实现. ECMAScript 5指定使用10(十进制),但不是所有浏览器 支持这个呢.因此,使用时请务必指定基数 parseInt.

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.

如果输入字符串以任何其他值开头,则基数为10 (十进制).

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

这篇关于棉绒警告:parseInt缺少基数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆