Search code examples
javascriptnumberslexical

about the number Literals lexical


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.


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.