aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/javascript/reference/errors/reserved_identifier/index.html
blob: 8a1932d9cc099971ff13b05a3892997ca7ea4fe6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
title: 'SyntaxError: "x" is a reserved identifier'
slug: Web/JavaScript/Reference/Errors/Reserved_identifier
tags:
  - 구문 에러
  - 예약어
  - 자바스크립트
translation_of: Web/JavaScript/Reference/Errors/Reserved_identifier
---
<div>{{jsSidebar("Errors")}}</div>

<h2 id="메세지">메세지</h2>

<pre class="syntaxbox">SyntaxError: The use of a future reserved word for an identifier is invalid (Edge)
SyntaxError: "x" is a reserved identifier (Firefox)
SyntaxError: Unexpected reserved word (Chrome)</pre>

<h2 id="에러_타입">에러 타입</h2>

<p>{{jsxref("SyntaxError")}}</p>

<h2 id="무엇이_잘못되었을까">무엇이 잘못되었을까?</h2>

<p><a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords">예약어</a>가 식별자로 쓰인 경우 발생하는 에러입니다. 이 키워드는 엄격(Strict) 모드와 느슨한(Sloppy) 모드에서 모두 예약어로 취급됩니다.</p>

<ul>
 <li><code>enum</code></li>
</ul>

<p>다음은 엄격 모드의 코드에서만 예약어로 취급됩니다:</p>

<ul class="threecolumns">
 <li><code>implements</code></li>
 <li><code>interface</code></li>
 <li>{{jsxref("Statements/let", "let")}}</li>
 <li><code>package</code></li>
 <li><code>private</code></li>
 <li><code>protected</code></li>
 <li><code>public</code></li>
 <li><code>static</code></li>
</ul>

<h2 id="예제">예제</h2>

<h3 id="엄격_모드와_엄격하지_않은_모드에서의_예약어">엄격 모드와 엄격하지 않은 모드에서의 예약어</h3>

<p><code>enum</code> 식별자는 일반적으로 예약되어 있습니다.</p>

<pre class="brush: js example-bad">var enum = { RED: 0, GREEN: 1, BLUE: 2 };
// SyntaxError: enum is a reserved identifier
</pre>

<p>엄격 모드의 코드에선 더 많은 식별자들이 예약되어 있습니다.</p>

<pre class="brush: js example-bad">"use strict";
var package = ["potatoes", "rice", "fries"];
// SyntaxError: package is a reserved identifier
</pre>

<p>이 변수들의 이름을 변경해야 합니다.</p>

<pre class="brush: js example-good">var colorEnum = { RED: 0, GREEN: 1, BLUE: 2 };
var list = ["potatoes", "rice", "fries"];</pre>

<h3 id="오래된_브라우저의_업데이트">오래된 브라우저의 업데이트</h3>

<p>새로운 구문을 사용하기 위해서는 최근 버전의 브라우저로 업데이트 해야 합니다. 예를 들어, 오래된 브라우저를 사용하고 있다면 <code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/let">let</a></code> 또는 <code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/class">class</a></code> 구현할 수 없습니다.</p>

<pre class="brush: js">"use strict";
class DocArchiver {}

// SyntaxError: class is a reserved identifier
// (오래된 버전의 브라우저에서만 에러가 발생합니다. 예) Firefox 44 이하)
</pre>

<h2 id="같이_보기">같이 보기</h2>

<ul>
 <li><a href="http://wiki.c2.com/?GoodVariableNames">Good variable names</a></li>
</ul>