Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top