When using the `parseInt()` function it is common to omit the second argument, the radix, and let the function try to determine from the first argument what type of number it is. By default, `parseInt()` will autodetect decimal and hexadecimal (via `0x` prefix). Prior to ECMAScript 5, `parseInt()` also autodetected octal literals, which caused problems because many developers assumed a leading `0` would be ignored.

This confusion led to the suggestion that you always use the radix parameter to `parseInt()` to eliminate unintended consequences. So instead of doing this:

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

Do this:

``````var num = parseInt("071", 10);  // 71
``````

ECMAScript 5 changed the behavior of `parseInt()` so that it no longer autodetects octal literals and instead treats them as decimal literals. However, the differences between hexadecimal and decimal interpretation of the first parameter causes many developers to continue using the radix parameter to ensure the string is interpreted in the intended way.

On the other hand, if the code is targeting only ES5-compliant environments passing the radix `10` may be redundant. In such a case you might want to disallow using such a radix.

## Rule Details

This rule is aimed at preventing the unintended conversion of a string to a number of a different base than intended or at preventing the redundant `10` radix if targeting modern environments only.

## Options

There are two options for this rule:

• `"always"` enforces providing a radix (default)
• `"as-needed"` disallows providing the `10` radix

### always

Examples of incorrect code for the default `"always"` option:

``````/*eslint radix: "error"*/

var num = parseInt("071");

var num = parseInt(someValue);

var num = parseInt("071", "abc");

var num = parseInt();
``````

Examples of correct code for the default `"always"` option:

``````/*eslint radix: "error"*/

var num = parseInt("071", 10);

var num = parseInt("071", 8);

var num = parseFloat(someValue);
``````

### as-needed

Examples of incorrect code for the `"as-needed"` option:

``````/*eslint radix: ["error", "as-needed"]*/

var num = parseInt("071", 10);

var num = parseInt("071", "abc");

var num = parseInt();
``````

Examples of correct code for the `"as-needed"` option:

``````/*eslint radix: ["error", "as-needed"]*/

var num = parseInt("071");

var num = parseInt("071", 8);

var num = parseFloat(someValue);
``````

## When Not To Use It

If you don’t want to enforce either presence or omission of the `10` radix value you can turn this rule off.
{"ft_lang_label":"__label__en","ft_lang_prob":0.5857275,"math_prob":0.94494826,"size":2501,"snap":"2020-45-2020-50","text_gpt3_token_len":583,"char_repetition_ratio":0.18021625,"word_repetition_ratio":0.22077923,"special_character_ratio":0.25669733,"punctuation_ratio":0.12195122,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97524405,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-10-28T02:54:19Z\",\"WARC-Record-ID\":\"<urn:uuid:bc4f2cb1-034f-4ebe-bbc1-f803d35bdf65>\",\"Content-Length\":\"20675\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:e116d082-cb3a-48e4-876d-3870b507aaea>\",\"WARC-Concurrent-To\":\"<urn:uuid:2e3c799e-b3d3-4992-a854-c0e691d35284>\",\"WARC-IP-Address\":\"185.199.111.153\",\"WARC-Target-URI\":\"http://eslint.cn/docs/6.0.0/rules/radix\",\"WARC-Payload-Digest\":\"sha1:W66WQNFQCY4S4J4D5RZHFHGMTYZMM6JS\",\"WARC-Block-Digest\":\"sha1:4ZL64OUXCDOL2GNJLH6QDRGAUK6JA57P\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-45/CC-MAIN-2020-45_segments_1603107896048.53_warc_CC-MAIN-20201028014458-20201028044458-00603.warc.gz\"}"}