Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
alert(010),结果是 8。为什么?我阅读了 ecmascript 7.8.3 Numeric Literals。根据 Numeric Literals Lexical,010 是无效的数字文字。
只有在开启严格模式时才会如此:
(function(){ "use strict"; 010; })(); SyntaxError: Octal literals are not allowed in strict mode.
否则会破坏向后兼容性。
010八进制是8十进制。如果它说它无效(链接在哪里?),它可能已经改变,或者你正在使用不是“ECMAScript”之类的不同版本进行操作?
010
8
在许多编程语言中,0数字文字之前的一个使其成为八进制。
0