문제

alert(010),the result is 8. why? i read the ecmascript 7.8.3 Numeric Literals. According to the Numeric Literals Lexical, 010 is a invalid numeric literals.

도움이 되었습니까?

해결책

It's only so when strict mode is turned on :

(function(){
"use strict";
010;
})();
SyntaxError: Octal literals are not allowed in strict mode.

Otherwise it would break backwards compatibility.

다른 팁

010 in octal is 8 in decimal. If it says it's invalid (where's the link?), it may have changed, or you're doing it in a different version that isn't "ECMAScript" or something?

In many programming languages, an 0 before a numeric literal makes it octal.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top