[‘1′,’2′,’3’]. Map (parseInt) results in some necessary instructions. Map is very simple to use, without saying too much about parseInt. And it also has an optional attribute, the radix, which we focus on this time. The radix of parseInt on MDN is valid from 2 to 36. If parseInt is 0, what happens to 1?
ParseInt (1, 0) parseInt(1, 1)
If the radix is undefined, 0, or unspecified, JavaScript assumes the following:
If the input string begins with “0x” or “0x” (a 0 followed by a lowercase or uppercase X), the radix is assumed to be 16 and the rest of the string is parsed into hexadecimal numbers. If the input string begins with “0” (0), the radix is assumed to be 8 (octal) or 10 (decimal). Which radix to choose depends on the implementation. ECMAScript 5 clarifies that 10 (decimal) should be used, but not all browsers support it. Therefore, it is important to specify a radix when using parseInt. If the input string begins with any other value, the radix is 10 (decimal). If radix=0, it is equivalent to the default base 10
ParsetInt (1, 0) // => 1 * 10^0 = 1 * 1 = 1
So let’s explain 1
1 indicates base 1. However, there is no clear explanation as to whether base 1 should be 0 or 1. See Zhihu for details
ParsetInt (1,1) becomes NaN directly
[‘1′,’2′,’3’]. Map (parseInt) = 1,NaN,NaN
It could actually be written like this
[‘1’, ‘2’, ‘3’]. Map (function (value, index) {return parseInt(value, index)}) parsetInt(‘1’, 0) = 1 index = 1: parsetInt(‘2’, 1) = NaN index = 2: ParsetInt (‘3’, 2) = NaN
[‘1’, ‘2’, ‘011’].map(parseInt) // 1,NaN,3