gpt4 book ai didi

JavaScript 谜题 : Not able to understand parseInt results in JavaScript

转载 作者:行者123 更新时间:2023-11-28 19:28:54 26 4
gpt4 key购买 nike

有人可以解释一下为什么我们在 JavaScript 中得到以下结果吗?

parseInt ( 'a' , 24 ) === 24 ;
>false
parseInt ( 'a' , 34 ) === 24 ;
>false
parseInt ( 'o' , 34 ) === 24 ;
>true

最佳答案

parseInt 的第二个参数是基数。

在 24 或 34 进制中,“a”等于 10,因为它是字母表的第一个字母,因此它是数字 0-9 之后使用的第一个数字。 'o' 是字母表中的第 15 个字母,因此它等于具有这么多数字的基数中的 24,就像您最后一个例子中的 34。

关于JavaScript 谜题 : Not able to understand parseInt results in JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27275109/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com