我不确定为什么会发生这种情况。
parseInt(1/8-9,23);
> -8
任何有关其工作原理的帮助都会很好。
最佳答案
这就是预期的答案。来自 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt :
If parseInt encounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point. parseInt truncates numbers to integer values
所以,-8.875
解析后,.
作为整数无效,因此它被 chop 为 -8
。自 8 < 23
, -8
在基地23
是 -8
关于javascript - 为什么 JavaScript 解释器得到 -8 作为语句 parseInt(1/8-9,23) 的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46181348/