Search code examples
javascriptecmascript-5octalstrict-mode

Why are Octal numeric literals not allowed in strict mode (and what is the workaround?)


Why are Octal numeric literals not allowed in JavaScript strict mode? What is the harm?

"use strict";
var x = 010; //Uncaught SyntaxError: Octal literals are not allowed in strict mode.
<h1>Check browser console for errors</h1>

In case a developer needs to use Octals (which can mistakenly change a numbers meaning), is there a workaround?


Solution

  • The "why" part of the question is not really answerable.

    As for "how", off the top of my head...

    "use strict";
    var x = parseInt('010', 8);
    document.write(x);