Frage

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.

War es hilfreich?

Lösung

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.

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top