JavaScript SyntaxError – “x” is not a legal ECMA-262 octal constant

This JavaScript warning 08 (or 09) is not a legal ECMA-262 octal constant occurs if the literals 08 or 09 are used as a number. This occurs because these literals cannot be treated as an octal number.

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:

Warning. JavaScript execution won't be halted.

Cause of Error: This happens when any of the digits after the leading 0 is equal or greater than 8. This number cannot be treated as an octal number and therefore JavaScript gives a warning about it.

Example 1: In this example, the literal ’08’ gives a warning because it can not be interpreted as octal number.



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
"use strict";
// Error here
08;
</script>

chevron_right


Output:

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

Example 2: In this example, the literal ’09’ gives a warning because it can not be interpreted as octal number.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
"use strict";
// Error here
09;
</script>

chevron_right


Output:

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

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.