gpt4 book ai didi

javascript - parseInt - 在 Node 环境中,使用基数

转载 作者:行者123 更新时间:2023-12-01 04:02:01 27 4
gpt4 key购买 nike

我找不到明确的答案,我们还需要使用基数(Node)吗?

let number = parseInt('666');

VS

let number = parseInt('666', 10);

最佳答案

将 MDN 填写至 parseInt :

If radix is undefined or 0 (or absent), JavaScript assumes the following:

  • If the input string begins with "0x" or "0X", radix is 16 (hexadecimal) and the remainder of the string is parsed.

  • If the input string begins with "0", radix is eight (octal) or 10 (decimal).  Exactly which radix is chosen is implementation-dependent.  ECMAScript 5 specifies that 10 (decimal) is 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).

关于javascript - parseInt - 在 Node 环境中,使用基数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42113420/

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