![]() |
If you put an octal literal in a code block that runs on strict, the result may be SyntaxError: Octal literals are not allowed in strict mode, since they can lead to unintended actions and confusion, numbers such as 0123 should never be strictly used, to understand this error better including possible causes, consider these examples. Understanding an errorIn JavaScript, strict mode is a way of voluntarily opting into a restricted variant of JavaScript for example catching common mistakes in coding and illegal actions like defining global variables, one of the restrictions is the prohibition against using octal literals in syntax, in earlier versions of JavaScript, octal literals were deprecated from the program’s structure when it was put in a stricter mode to avoid ambiguity. Case 1: Using Octal Literals in Strict ModeError Cause:When an octal literal is used in strict mode a syntax error is raised because syntax errors related to octal literals are not allowed when using strict mode. Example: "use strict"; Output: SyntaxError: Octal literals are not allowed in strict mode. Resolution of error:To avoid such error you should not use octal literals in strict mode to solve this problem, it can be represented by its decimal format or another notation for octal numbers.
Output 123 Case 2: Using Octal Literals with the |
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 20 |