aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/javascript/reference/errors/no_variable_name/index.html
blob: e9d6ec6ee7162519a2e33ca76ba58c0f865ff4af (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
---
title: 'SyntaxError: missing variable name'
slug: Web/JavaScript/Reference/Errors/No_variable_name
translation_of: Web/JavaScript/Reference/Errors/No_variable_name
---
<div>{{jsSidebar("Errors")}}</div>

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

<pre class="syntaxbox">SyntaxError: missing variable name (Firefox)
SyntaxError: Unexpected token = (Chrome)</pre>

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

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

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

<p>변수에 이름이 없습니다. 이것은 코드 내의 구문 에러 때문일 수도 있습니다. 어쩌면 콤마를 잘 못 된 곳에 찍었거나, 변수명을 지을 때 애를 먹었을 수도 있습니다. 그럴 수도 있죠! 작명은 너무 어려우니까요. </p>

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

<h3 id="이름을_잃은_변수">이름을 잃은 변수</h3>

<pre class="brush: js example-bad">var = "foo";
</pre>

<p>좋은 이름을 떠올리기 어려웠을 거예요. 우리 모두 겪는 일이죠.</p>

<pre class="brush: js example-good">var ohGodWhy = "foo";</pre>

<h3 id="예약어는_변수명이_될_수_없어요">예약어는 변수명이 될 수 없어요</h3>

<p>예약어로 지정된 이름들이 변수로 쓰여 있습니다. 이것들은 사용할 수 없어요. 미안합니다. :(</p>

<pre class="brush: js example-bad">var debugger = "whoop";
// SyntaxError: missing variable name
</pre>

<h3 id="여러_변수를_선언하기">여러 변수를 선언하기</h3>

<p>여러 변수를 한 번에 선언할 때에는 콤마에 주의를 기울여야 합니다. 쓸 데없는 콤마를 더 찍지는 않았는지? 무심코 세미콜론 대신 콤마를 찍지는 않았는지? </p>

<pre class="brush: js example-bad">var x, y = "foo",
var x, = "foo"

var first = document.getElementById('one'),
var second = document.getElementById('two'),

// SyntaxError: missing variable name
</pre>

<p>올바르게 수정한 버전:</p>

<pre class="brush: js example-good">var x, y = "foo";
var x = "foo";

var first = document.getElementById('one');
var second = document.getElementById('two');</pre>

<h3 id="배열">배열</h3>

<p>JavaScript 의 {{jsxref("Array")}} 리터럴은 대괄호로 감싸주어야 합니다. 이건 동작하지 않아요.</p>

<pre class="brush: js example-bad">var arr = 1,2,3,4,5;
// SyntaxError: missing variable name
</pre>

<p>이렇게 해야 맞습니다:</p>

<pre class="brush: js example-good">var arr = [1,2,3,4,5];</pre>

<h2 id="더_보기">더 보기</h2>

<ul>
 <li><a href="http://wiki.c2.com/?GoodVariableNames">Good variable names</a></li>
 <li><code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/var">var</a></code></li>
 <li><a href="/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Declarations">Variable declarations in the JavaScript Guide</a></li>
</ul>