codestates / codestates/DEVzine-port
[ERROR LOG] Uncaught SyntaxError: Octal literals are not allowed in strict mode.
- Dominant language
- JavaScript
- Stars
- 1
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
## Error Type
- Uncaught SyntaxError
## Error Message
```shell
Uncaught SyntaxError: Octal literals are not allowed in strict mode.
```
## Solution
- `JS`에서는 정수 리터럴에서 0으로 시작할 경우 8진수임을 나타낸다.
> 정수 리터럴에서 선행 0(zero)이나 선행 0o(혹은 0O)은 8진수임을 나타냅니다. 8진 정수는 오직 숫자 0-7만 포함할 수 있습니다. (출처 : `mdn`)
- 8진 literal은 더이상 사용하지 않으므로 `use strict`모드 에서는 `syntax error`를 날리는데
- 숫자 0뒤에 영어 소문자 o를 넣음으로 8진수를 사용할 수 있다.
아래는 `use strict`에서 8진 리터럴이 더이상 사용하지 못함을 실험하기 위한 코드 이다.
```js
(() => {
'use strict';
console.log(010);
})();
//Uncaught SyntaxError: Octal literals are not allowed in strict mode.
```
```js
(() => {
console.log(010);
})();
//8
```
## Reference
- [mdn octal](https://developer.mozilla.org/ko/docs/Web/JavaScript/Guide/Grammar_and_types)
- [mdn SyntaxError: "0"-prefixed octal literals and octal escape seq. are deprecated](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Errors/Deprecated_octal)
- [stackoverflow](https://stackoverflow.com/questions/23609042/how-to-avoid-octal-literals-are-not-allowed-in-strict-mode-with-createwritestr)
- [runebook](https://runebook.dev/ko/docs/javascript/errors/deprecated_octal)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.