gpt4 book ai didi

javascript - 在控制台中写入数字时出现奇怪的行为

转载 作者:行者123 更新时间:2023-11-29 19:45:17 25 4
gpt4 key购买 nike

<分区>

数字的

console.log() 表现不同。

以下发现很有趣。有什么解释吗?

console.log(1) - 1

console.log(01) - 1

console.log(12) - 12

console.log(012) - 10

console.log(0123) - 83

console.log(123) - 123

编辑

MDN documentation: 中找到这个

Integers can be expressed in decimal (base 10), hexadecimal (base 16), and octal (base 8).

Decimal integer literal consists of a sequence of digits without a leading 0 (zero).
Leading 0 (zero) on an integer literal indicates it is in octal. Octal integers can include only the digits 0-7.
Leading 0x (or 0X) indicates hexadecimal. Hexadecimal integers can include digits (0-9) and the letters a-f and A-F.
Octal integer literals are deprecated and have been removed from the ECMA-262, Edition 3 standard (in strict mode). JavaScript 1.5 still supports them for backward compatibility.

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