为什么 parseInt('60', 10)
与 parseInt('60', 0)
相同?
JavaScript 将 0 基数转换成什么?
最佳答案
来自 MDN ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt )
If the radix is undefined, 0, or unspecified, JavaScript assumes the following:
If the input string begins with "0x" or "0X" (a zero followed by lowercase or uppercase X), radix is assumed to be 16 and the rest of the string is parsed as a hexidecimal number.
If the input string begins with "0" (a zero), radix is assumed to be 8 (octal) or 10 (decimal). Exactly which radix is chosen is implementation-dependent. ECMAScript 5 clarifies that 10 (decimal) should be used, but not all browsers support this yet. For this reason always specify a radix when using parseInt.
If the input string begins with any other value, the radix is 10 (decimal).
因此,如果解析的输入从“0”开始,结果取决于浏览器。
关于javascript - 为什么 parseInt(x,0) 与 parseInt(x, 10) 相同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56458990/