JSLint says “missing radix parameter”

前端 未结 11 1269
北荒
北荒 2020-11-30 17:10

I ran JSLint on this JavaScript code and it said:

Problem at line 32 character 30: Missing radix parameter.

This is the code i

11条回答
  •  粉色の甜心
    2020-11-30 17:46

    It always a good practice to pass radix with parseInt -

    parseInt(string, radix)
    

    For decimal -

    parseInt(id.substring(id.length - 1), 10)
    

    If the radix parameter is omitted, JavaScript assumes the following:

    • If the string begins with "0x", the radix is 16 (hexadecimal)
    • If the string begins with "0", the radix is 8 (octal). This feature is deprecated
    • If the string begins with any other value, the radix is 10 (decimal)

    (Reference)

提交回复
热议问题