JSLint says “missing radix parameter”

前端 未结 11 1265
北荒
北荒 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:27

    To avoid this warning, instead of using:

    parseInt("999", 10);
    

    You may replace it by:

    Number("999");
    


    Note that parseInt and Number have different behaviors, but in some cases, one can replace the other.

    0 讨论(0)
  • 2020-11-30 17:28

    Instead of calling the substring function you could use .slice()

        imageIndex = parseInt(id.slice(-1)) - 1;
    

    Here, -1 in slice indicates that to start slice from the last index.

    Thanks.

    0 讨论(0)
  • 2020-11-30 17:29

    Prior to ECMAScript 5, parseInt() also autodetected octal literals, which caused problems because many developers assumed a leading 0 would be ignored.

    So Instead of :

    var num = parseInt("071");      // 57
    

    Do this:

    var num = parseInt("071", 10);  // 71
    
    var num = parseInt("071", 8);
    
    var num = parseFloat(someValue); 
    

    Reference

    0 讨论(0)
  • 2020-11-30 17:31

    You can turn off this rule if you wish to skip that test.

    Insert:

    radix: false
    

    Under the "rules" property in the tslint.json file.

    It's not recommended to do that if you don't understand this exception.

    0 讨论(0)
  • 2020-11-30 17:34

    Adding the following on top of your JS file will tell JSHint to supress the radix warning:

    /*jshint -W065 */
    

    See also: http://jshint.com/docs/#options

    0 讨论(0)
  • 2020-11-30 17:37

    Simply add your custom rule in .eslintrc which looks like that "radix": "off" and you will be free of this eslint unnesesery warning. This is for the eslint linter.

    0 讨论(0)
提交回复
热议问题