javascript - parseInt() 字符串哈希返回整数

标签 javascript string parsing

我有一个哈希作为 ID,我不小心使用了 parseInt()。

我想知道为什么它返回一个实际的整数 (7) 而不是 NaN

const hash = "7bb94588-4f62-4c41-a782-e5164844cc0d";
console.log(hash);
console.log(typeof hash);
console.log(parseInt(hash))

这并不是一个需要帮助的问题...但我想更好地了解 JS 的工作原理。

最佳答案

根据spec

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.

关于javascript - parseInt() 字符串哈希返回整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47338982/

相关文章:

C# string[] 到 int[]

javascript - 为什么我的 Ajax 会调用两次 fire ?

java - 将概率分配给随机枚举对象

c - 用 C 语言实现相同算法的 MIPS 程序

Java - 提取后缀和前缀中间的字符串

php - 如何在 PHP 中解析 JSON 对象?

javascript - jQuery - 在 iframe 内按钮的 onclick 事件中更改 iframe 高度

php - ajax POST 不起作用,不明白为什么

javascript - jQuery 点击 td 切换复选框

包含 .ini 数据的字符串的 javascript 解析器