Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1065392 of SyntaxError: "x" is not a legal ECMA-262 octal constant

  • Revision slug: Web/JavaScript/Reference/Errors/Bad_octal
  • Revision title: SyntaxError: "x" is not a legal ECMA-262 octal constant
  • Revision id: 1065392
  • Created:
  • Creator: fscholz
  • Is current revision? Yes
  • Comment new page

Revision Content

{{jsSidebar("Errors")}}

Message

Warning: SyntaxError: 08 is not a legal ECMA-262 octal constant.
Warning: SyntaxError: 09 is not a legal ECMA-262 octal constant.

Error type

{{jsxref("SyntaxError")}} warning in strict mode only.

What went wrong?

Decimal literals can start with a zero (0) followed by another decimal digit, but If all digits after the leading 0 are smaller than 8, the number is interpreted as an octal number. Because this is not the case with 08 and 09, JavaScript warns about it.

Note that octal literals and octal escape sequences are deprecated and will present an additional deprecation warning. With ECMAScript 6 and later, the syntax uses a leading zero followed by a lowercase or uppercase Latin letter "O" (0o or 0O). See the page about lexical grammar for more information.

Examples

Invalid octal numbers

08;
09;
// SyntaxError: 08 is not a legal ECMA-262 octal constant
// SyntaxError: octal literals and octal escape sequences are deprecated

Valid octal numbers

Use a leading zero followed by the letter "o";

0O755;
0o644;

See also

Revision Source

<div>{{jsSidebar("Errors")}}</div>

<h2 id="Message">Message</h2>

<pre class="syntaxbox">
Warning: SyntaxError: 08 is not a legal ECMA-262 octal constant.
Warning: SyntaxError: 09 is not a legal ECMA-262 octal constant.
</pre>

<h2 id="Error_type">Error type</h2>

<p>{{jsxref("SyntaxError")}} warning in <a href="/en-US/docs/Web/JavaScript/Reference/Strict_mode">strict mode</a> only.</p>

<h2 id="What_went_wrong">What went wrong?</h2>

<p>Decimal literals can start with a zero (<code>0</code>) followed by another decimal digit, but If all digits after the leading <code>0</code> are smaller than 8, the number is interpreted as an octal number. Because this is not the case with <code>08</code> and <code>09</code>, JavaScript warns about it.</p>

<p>Note that octal literals and octal escape sequences are deprecated and will present an additional deprecation warning. With ECMAScript 6 and later, the syntax uses a leading zero followed by a lowercase or uppercase Latin letter "O" (<code>0o</code> or <code>0O)</code>. See the page about <a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Octal">lexical grammar</a> for more information.</p>

<h2 id="Examples">Examples</h2>

<h3>Invalid octal numbers</h3>

<pre class="brush: js example-bad">
08;
09;
// SyntaxError: 08 is not a legal ECMA-262 octal constant
// SyntaxError: octal literals and octal escape sequences are deprecated</pre>

<h3>Valid octal numbers</h3>

<p>Use a leading zero followed by the letter "o";</p>

<pre class="brush: js example-good">
0O755;
0o644;
</pre>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Octal">Lexical grammar</a></li>
</ul>
Revert to this revision