The result of 1/0
is Infinity
.
(1/0
的结果是Infinity
。)
parseInt
treats its first argument as a string which means first of all Infinity.toString()
is called, producing the string "Infinity"
.
(parseInt
将其第一个参数视为字符串,这意味着首先调用Infinity.toString()
,生成字符串"Infinity"
。)
So it works the same as if you asked it to convert "Infinity"
in base 19 to decimal. (因此它的工作原理与您要求它将基数19中的"Infinity"
转换为十进制相同。)
Here are the digits in base 19 along with their decimal values:
(以下是基数19中的数字及其小数值:)
Base 19 Base 10 (decimal)
---------------------------
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
a 10
b 11
c 12
d 13
e 14
f 15
g 16
h 17
i 18
What happens next is that parseInt
scans the input "Infinity"
to find which part of it can be parsed and stops after accepting the first I
(because n
is not a valid digit in base 19).
(接下来发生的是parseInt
扫描输入"Infinity"
以找到它的哪个部分可以被解析并在接受第一个I
之后停止(因为n
不是基数19中的有效数字)。)
Therefore it behaves as if you called parseInt("I", 19)
, which converts to decimal 18 by the table above.
(因此,它的行为就像你调用了parseInt("I", 19)
,它被上面的表转换为十进制18。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…