about the number Literals lexical
-
02-06-2021 - |
Domanda
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.
Soluzione
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.
Altri suggerimenti
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.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow