aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/javascript/reference/lexical_grammar/index.html
blob: 74e4e6378888a6a8579319c5292df75fb5ef12cc (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
---
title: 어휘 문법
slug: Web/JavaScript/Reference/Lexical_grammar
tags:
  - JavaScript
  - Keyword
  - Lexical Grammar
  - 문법
translation_of: Web/JavaScript/Reference/Lexical_grammar
---
<div>{{JsSidebar("More")}}</div>

<p>이 페이지는 JavaScript의 어휘 문법(lexical grammar)을 설명합니다. ECMAScript 소스 본문은 왼쪽에서 오른쪽 방향으로 분석되고 토큰, 제어문자, 줄바꿈, 주석, 또는 공백으로 구성되는 입력 요소 시퀀스로 바뀝니다. 또한 ECMAScript는 특별한 키워드와 리터럴을 정의하고 있으며 명령문 끝에 자동으로 세미콜론을 추가하는 규칙이 있습니다.</p>

<h2 id="제어_문자">제어 문자</h2>

<p>제어 문자는 눈에 보이지 않지만 스크립트 소스 본문 해석을 제어하는 데 사용됩니다.</p>

<table class="standard-table">
 <caption>유니코드 형식 제어 문자</caption>
 <tbody>
  <tr>
   <th>코드 포인트</th>
   <th>이름</th>
   <th>축약형</th>
   <th>설명</th>
  </tr>
  <tr>
   <td><code>U+200C</code></td>
   <td>Zero width non-joiner</td>
   <td>&lt;ZWNJ&gt;</td>
   <td>
    <p>특정 언어에서 문자들이 연결선으로 묶이지 않게 하기 위해 문자 사이에 위치한다(<a href="http://en.wikipedia.org/wiki/Zero-width_non-joiner">Wikipedia</a>).</p>
   </td>
  </tr>
  <tr>
   <td><code>U+200D</code></td>
   <td>Zero width joiner</td>
   <td>&lt;ZWJ&gt;</td>
   <td>
    <p>특정 언어에서, 보통은 연결되지 않는 문자이나 해당 문자를 연결된 형태로 그리기 위해서(to be rendered) 사용하며 문자 사이에 위치한다(<a href="http://en.wikipedia.org/wiki/Zero-width_joiner">Wikipedia</a>).</p>
   </td>
  </tr>
  <tr>
   <td><code>U+FEFF</code></td>
   <td>Byte order mark</td>
   <td>&lt;BOM&gt;</td>
   <td>
    <p>스크립트 맨 앞에 두어 스크립트 본문의 byte order와 유니코드를 표시하는 데에 사용한다.(<a href="http://en.wikipedia.org/wiki/Byte_order_mark">Wikipedia</a>).</p>
   </td>
  </tr>
 </tbody>
</table>

<h2 id="공백">공백</h2>

<p>공백 문자는 소스 본문을 읽기 좋게 만들고 토큰을 구분합니다. 이 공백 문자들은 보통 코드의 기능에 필요한 것은 아닙니다. 최소화 도구(<a href="http://en.wikipedia.org/wiki/Minification_%28programming%29">Minification tools</a>)는 종종 전송해야하는 데이터 크기를 줄이기 위해서 공백을 제거합니다.</p>

<table class="standard-table">
 <caption>공백 문자</caption>
 <tbody>
  <tr>
   <th>코드 포인트</th>
   <th>이름</th>
   <th>축약형</th>
   <th>설명</th>
   <th>이스케이프 시퀀스</th>
  </tr>
  <tr>
   <td>U+0009</td>
   <td>Character tabulation</td>
   <td>&lt;HT&gt;</td>
   <td>Horizontal tabulation</td>
   <td>\t</td>
  </tr>
  <tr>
   <td>U+000B</td>
   <td>Line tabulation</td>
   <td>&lt;VT&gt;</td>
   <td>Vertical tabulation</td>
   <td>\v</td>
  </tr>
  <tr>
   <td>U+000C</td>
   <td>Form feed</td>
   <td>&lt;FF&gt;</td>
   <td>Page breaking control character (<a href="http://en.wikipedia.org/wiki/Page_break#Form_feed">Wikipedia</a>).</td>
   <td>\f</td>
  </tr>
  <tr>
   <td>U+0020</td>
   <td>Space</td>
   <td>&lt;SP&gt;</td>
   <td>Normal space</td>
   <td></td>
  </tr>
  <tr>
   <td>U+00A0</td>
   <td>No-break space</td>
   <td>&lt;NBSP&gt;</td>
   <td>Normal space, but no point at which a line may break</td>
   <td></td>
  </tr>
  <tr>
   <td>Others</td>
   <td>Other Unicode space characters</td>
   <td>&lt;USP&gt;</td>
   <td><a href="http://en.wikipedia.org/wiki/Space_%28punctuation%29#Spaces_in_Unicode">Spaces in Unicode on Wikipedia</a></td>
   <td></td>
  </tr>
 </tbody>
</table>

<h2 id="개행_문자">개행 문자</h2>

<p>공백문자와 더불어, 개행 문자는 소스 본문의 가독성을 향상시킵니다. 하지만, 몇몇 상황에서 개행 문자는 코드 내부에 숨겨지기 때문에 자바스크립트 코드 실행에 영향을 미칩니다. 개행 문자는 자동 새미콜론 삽입(<a href="#Automatic_semicolon_insertion">automatic semicolon insertion</a>) 규칙에도 영향을 줍니다. 개행 문자는 표준 표현방식(<a href="/en-US/docs/Web/JavaScript/Guide/Regular_Expressions">regular expressions</a>)의 클래스인 \s로 매치됩니다.</p>

<p>아래의 유니코드 문자만이 ECMAScript에서 라인 종결자로 다뤄지며, 라인을 바꾸는 다른 문자들은 공백으로 생각하시면 됩니다(예를 들어, Next Line, NEL, U+0085는 공백으로 간주).</p>

<table class="standard-table">
 <caption>개행 문자</caption>
 <tbody>
  <tr>
   <th>코드 포인트</th>
   <th>이름</th>
   <th>축약형</th>
   <th>설명</th>
   <th>이스케이프 시퀀스</th>
  </tr>
  <tr>
   <td>U+000A</td>
   <td>Line Feed</td>
   <td>&lt;LF&gt;</td>
   <td>New line character in UNIX systems.</td>
   <td>\n</td>
  </tr>
  <tr>
   <td>U+000D</td>
   <td>Carriage Return</td>
   <td>&lt;CR&gt;</td>
   <td>New line character in Commodore and early Mac systems.</td>
   <td>\r</td>
  </tr>
  <tr>
   <td>U+2028</td>
   <td>Line Separator</td>
   <td>&lt;LS&gt;</td>
   <td><a href="http://en.wikipedia.org/wiki/Newline">Wikipedia</a></td>
   <td></td>
  </tr>
  <tr>
   <td>U+2029</td>
   <td>Paragraph Separator</td>
   <td>&lt;PS&gt;</td>
   <td><a href="http://en.wikipedia.org/wiki/Newline">Wikipedia</a></td>
   <td></td>
  </tr>
 </tbody>
</table>

<h2 id="주석">주석</h2>

<p>주석은 힌트, 필기, 제안이나 주의할 점들을 자바스크립트 코드에 넣을 때 사용합니다. 이는 더 쉽게 읽고 이해할 수 있게 도와줍니다. 또한 특정 코드가 실행되지 않도록 막아주기도 합니다. 따라서 주석은 유용한 디버깅 도구라고도 할 수 있습니다.</p>

<p>자바스크립트에는 코드 속에 주석을 쓰는 두 가지 방식이 있습니다.</p>

<p>첫 번째, '//'로 첨언하기입니다. 이는 아래의 예시처럼 같은 줄에 있는 모든 코드를 주석으로 바꿉니다.</p>

<pre class="brush: js notranslate">function comment() {
  // 자바스크립트의 각주 한 줄입니다.
  console.log("Hello world!");
}
comment();
</pre>

<p>두 번째, 좀 더 유연하게 쓸 수 있는 '/* */'로 첨언하기입니다.</p>

<p>예를 들면, 한 줄에 첨언할 때는 이렇게 쓸 수 있습니다 :</p>

<pre class="brush: js notranslate">function comment() {
  /* 자바스크립트 각주 한 줄입니다. */
  console.log("Hello world!");
}
comment();</pre>

<p>여러 줄로 첨언할 때는, 이렇게 씁니다 :</p>

<pre class="brush: js notranslate">function comment() {
  /* This comment spans multiple lines. Notice
     that we don't need to end the comment until we're done. */
  console.log("Hello world!");
}
comment();</pre>

<p>원한다면, 라인 중간에도 사용할 수 있습니다. 물론 코드의 가독성이 떨어지게 됩니다. 그러니 주의를 기울여 사용해야 합니다:</p>

<p>function comment(x) {</p>

<pre class="brush: js notranslate">  console.log("Hello " + x /* insert the value of x */ + " !");
}
comment("world");</pre>

<p>게다가, 코드 실행을 막기 위해 코드를 무용화 시키는데도 사용할 수 있습니다. 아래처럼 코드를 코멘트로 감싸는 거죠:</p>

<pre class="brush: js notranslate">function comment() {
  /* console.log("Hello world!"); */
}
comment();</pre>

<p>In this case, the <code>console.log()</code> call is never issued, since it's inside a comment. Any number of lines of code can be disabled this way.</p>

<h2 id="해시뱅_주석">해시뱅 주석</h2>

<p>A specialized third comment syntax, the <strong>hashbang comment</strong>, is in the process of being standardized in ECMAScript (see the <a href="https://github.com/tc39/proposal-hashbang">Hashbang Grammar proposal</a>).</p>

<p>A hashbang comment behaves exactly like a single line-only (<code>//</code>) comment, but it instead begins with <code>#!</code> and<strong> is only valid at the absolute start of a script or module</strong>. Note also that no whitespace of any kind is permitted before the <code>#!</code>. The comment consists of all the characters after <code>#!</code> up to the end of the first line; only one such comment is permitted.</p>

<p>The hashbang comment specifies the path to a specific JavaScript interpreter<br>
 that you want to use to execute the script. An example is as follows:</p>

<pre class="brush: js notranslate">#!/usr/bin/env node

console.log("Hello world");
</pre>

<div class="blockIndicator note">
<p><strong>Note</strong>: Hashbang comments in JavaScript mimic <a href="https://en.wikipedia.org/wiki/Shebang_(Unix)">shebangs in Unix</a> used to run files with proper interpreter.</p>
</div>

<div class="blockIndicator warning">
<p>Although <a href="https://en.wikipedia.org/wiki/Byte_order_mark">BOM</a> before hashbang comment will work in a browser it is not advised to use BOM in a script with hasbang. BOM will not work when you try to run the script in Unix/Linux. So use UTF-8 without BOM if you want to run scripts directly from shell.</p>
</div>

<p>You must only use the <code>#!</code> comment style to specify a JavaScript interpreter. In all other cases just use a <code>//</code> comment (or mulitiline comment).</p>

<h2 id="키워드">키워드</h2>

<h3 id="ECMAScript_2015_기준_예약_키워드">ECMAScript 2015 기준 예약 키워드</h3>

<ul class="threecolumns">
 <li>{{jsxref("Statements/break", "break")}}</li>
 <li>{{jsxref("Statements/switch", "case")}}</li>
 <li>{{jsxref("Statements/try...catch", "catch")}}</li>
 <li>{{jsxref("Statements/class", "class")}}</li>
 <li>{{jsxref("Statements/const", "const")}}</li>
 <li>{{jsxref("Statements/continue", "continue")}}</li>
 <li>{{jsxref("Statements/debugger", "debugger")}}</li>
 <li>{{jsxref("Statements/default", "default")}}</li>
 <li>{{jsxref("Operators/delete", "delete")}}</li>
 <li>{{jsxref("Statements/do...while", "do")}}</li>
 <li>{{jsxref("Statements/if...else", "else")}}</li>
 <li>{{jsxref("Statements/export", "export")}}</li>
 <li>{{jsxref("Statements/class", "extends")}}</li>
 <li>{{jsxref("Statements/try...catch", "finally")}}</li>
 <li>{{jsxref("Statements/for", "for")}}</li>
 <li>{{jsxref("Statements/function", "function")}}</li>
 <li>{{jsxref("Statements/if...else", "if")}}</li>
 <li>{{jsxref("Statements/import", "import")}}</li>
 <li>{{jsxref("Operators/in", "in")}}</li>
 <li>{{jsxref("Operators/instanceof", "instanceof")}}</li>
 <li>{{jsxref("Operators/new", "new")}}</li>
 <li>{{jsxref("Statements/return", "return")}}</li>
 <li>{{jsxref("Operators/super", "super")}}</li>
 <li>{{jsxref("Statements/switch", "switch")}}</li>
 <li>{{jsxref("Operators/this", "this")}}</li>
 <li>{{jsxref("Statements/throw", "throw")}}</li>
 <li>{{jsxref("Statements/try...catch", "try")}}</li>
 <li>{{jsxref("Operators/typeof", "typeof")}}</li>
 <li>{{jsxref("Statements/var", "var")}}</li>
 <li>{{jsxref("Operators/void", "void")}}</li>
 <li>{{jsxref("Statements/while", "while")}}</li>
 <li>{{jsxref("Statements/with", "with")}}</li>
 <li>{{jsxref("Operators/yield", "yield")}}</li>
</ul>

<h3 id="확장_예약_키워드">확장 예약 키워드</h3>

<p>The following are reserved as future keywords by the ECMAScript specification. They have no special functionality at present, but they might at some future time, so they cannot be used as identifiers.</p>

<p>These are always reserved:</p>

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

<p>The following are only reserved when they are found in strict mode code:</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>

<p>The following are only reserved when they are found in module code:</p>

<ul>
 <li><code>await</code></li>
</ul>

<h4 id="구형_표준의_확장_예약_키워드">구형 표준의 확장 예약 키워드</h4>

<p>The following are reserved as future keywords by older ECMAScript specifications (ECMAScript 1 till 3).</p>

<ul class="threecolumns">
 <li><code>abstract</code></li>
 <li><code>boolean</code></li>
 <li><code>byte</code></li>
 <li><code>char</code></li>
 <li><code>double</code></li>
 <li><code>final</code></li>
 <li><code>float</code></li>
 <li><code>goto</code></li>
 <li><code>int</code></li>
 <li><code>long</code></li>
 <li><code>native</code></li>
 <li><code>short</code></li>
 <li><code>synchronized</code></li>
 <li><code>throws</code></li>
 <li><code>transient</code></li>
 <li><code>volatile</code></li>
</ul>

<p>Additionally, the literals <code>null</code>, <code>true</code>, and <code>false</code> cannot be used as identifiers in ECMAScript.</p>

<h3 id="예약어_사용법">예약어 사용법</h3>

<p>Reserved words actually only apply to Identifiers (vs. <code>IdentifierNames</code>) . As described in <a href="http://es5.github.com/#A.1">es5.github.com/#A.1</a>, these are all <code>IdentifierNames</code> which do not exclude <code>ReservedWords</code>.</p>

<pre class="brush: js notranslate">a.import
a['import']
a = { import: 'test' }.
</pre>

<p>On the other hand the following is illegal because it's an <code>Identifier</code>, which is an <code>IdentifierName</code> without the reserved words. Identifiers are used for <code>FunctionDeclaration, FunctionExpression, VariableDeclaration</code> and so on. <code>IdentifierNames </code>are used for<code> MemberExpression, CallExpression</code> and so on.</p>

<pre class="brush: js notranslate">function import() {} // Illegal.</pre>

<h2 id="리터럴">리터럴</h2>

<h3 id="Null_리터럴">Null 리터럴</h3>

<p>See also <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/null"><code>null</code></a> for more information.</p>

<pre class="brush: js notranslate">null</pre>

<h3 id="불리언_리터럴">불리언 리터럴</h3>

<p>See also <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean"><code>Boolean</code></a> for more information.</p>

<pre class="brush: js notranslate">true
false</pre>

<h3 id="숫자_리터럴">숫자 리터럴</h3>

<h4 id="10진법">10진법</h4>

<pre class="brush: js notranslate">1234567890
42

// Caution when using with a leading zero:
0888 // 888 parsed as decimal
0777 // parsed as octal, 511 in decimal
</pre>

<p>Note that decimal literals can start with a zero (<code>0</code>) followed by another decimal digit, but If all digits after the leading <code>0</code> are smaller than 8, the number is interpreted as an octal number. This won't throw in JavaScript, see {{bug(957513)}}. See also the page about <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt#Octal_interpretations_with_no_radix"><code>parseInt()</code></a>.</p>

<h5 id="Exponential">Exponential</h5>

<p>The decimal exponential literal is specified by the following format: <code>beN</code>; where <code>b</code> is a base number (integer or floating), followed by <code>e</code> char (which serves as separator or <em>exponent indicator</em>) and<em> </em><code>N</code>, which is <em>exponent</em> or <em>power</em> number – a signed integer (as per 2019 ECMA-262 specs): </p>

<pre class="notranslate">0e-5   // =&gt; 0
0e+5   // =&gt; 0
5e1    // =&gt; 50
175e-2 // =&gt; 1.75
1e3    // =&gt; 1000
1e-3   // =&gt; 0.001</pre>

<h4 id="2진법">2진법</h4>

<p>Binary number syntax uses a leading zero followed by a lowercase or uppercase Latin letter "B" (<code>0b</code> or <code>0B</code>). Because this syntax is new in ECMAScript 2015, see the browser compatibility table, below. If the digits after the <code>0b</code> are not 0 or 1, the following <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError">SyntaxError</a></code> is thrown: "Missing binary digits after 0b".</p>

<pre class="brush: js notranslate">var FLT_SIGNBIT  = 0b10000000000000000000000000000000; // 2147483648
var FLT_EXPONENT = 0b01111111100000000000000000000000; // 2139095040
var FLT_MANTISSA = 0B00000000011111111111111111111111; // 8388607</pre>

<h4 id="8진법">8진법</h4>

<p>Octal number syntax uses a leading zero followed by a lowercase or uppercase Latin letter "O" (<code>0o</code> or <code>0O)</code>. Because this syntax is new in ECMAScript 2015, see the browser compatibility table, below. If the digits after the <code>0o</code> are outside the range (01234567), the following <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError">SyntaxError</a></code> is thrown: "Missing octal digits after 0o".</p>

<pre class="brush: js notranslate">var n = 0O755; // 493
var m = 0o644; // 420

// Also possible with just a leading zero (see note about decimals above)
0755
0644
</pre>

<h4 id="16진법">16진법</h4>

<p>Hexadecimal number syntax uses a leading zero followed by a lowercase or uppercase Latin letter "X" (<code>0x</code> or <code>0X)</code>. If the digits after 0x are outside the range (0123456789ABCDEF), the following <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError">SyntaxError</a></code> is thrown: "Identifier starts immediately after numeric literal".</p>

<pre class="brush: js notranslate">0xFFFFFFFFFFFFFFFFF // 295147905179352830000
0x123456789ABCDEF   // 81985529216486900
0XA                 // 10
</pre>

<h4 id="BigInt_literal">BigInt literal</h4>

<p>The {{jsxref("BigInt")}} type is a numeric primitive in JavaScript that can represent integers with arbitrary precision. BigInt literals are created by appending <code>n</code> to the end of an integer.</p>

<pre class="notranslate">123456789123456789n     // 123456789123456789
0o777777777777n         // 68719476735
0x123456789ABCDEFn      // 81985529216486895‬
0b11101001010101010101n // 955733
</pre>

<p>Note that legacy octal numbers with just a leading zero won't work for <code>BigInt</code>:</p>

<pre class="example-bad notranslate">// 0755n
// SyntaxError: invalid BigInt syntax</pre>

<p>For octal <code>BigInt</code> numbers, always use zero followed by the letter "o" (uppercase or lowercase):</p>

<pre class="example-good notranslate">0o755n</pre>

<p>For more information about <code>BigInt</code>, see also <a href="https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#BigInt_type">JavaScript data structures</a>.</p>

<h4 id="Numeric_separators">Numeric separators</h4>

<p>To improve readability for numeric literals, underscores (<code>_</code><code>U+005F</code>) can be used as separators:</p>

<pre class="notranslate">// separators in decimal numbers
1_000_000_000_000
1_050.95

// separators in binary numbers
0b1010_0001_1000_0101

// separators in octal numbers
0o2_2_5_6

// separators in hex numbers
0xA0_B0_C0

// separators in BigInts
1_000_000_000_000_000_000_000n
</pre>

<p>Note these limitations:</p>

<pre class="example-bad notranslate">// More than one underscore in a row is not allowed
100__000; // SyntaxError

// Not allowed at the end of numeric literals
100_; // SyntaxError

// Can not be used after leading 0
0_1; // SyntaxError
</pre>

<h3 id="객체_리터럴">객체 리터럴</h3>

<p>See also {{jsxref("Object")}} and <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer">Object initializer</a> for more information.</p>

<pre class="brush: js notranslate">var o = { a: 'foo', b: 'bar', c: 42 };

// shorthand notation. New in ES2015
var a = 'foo', b = 'bar', c = 42;
var o = {a, b, c};

// instead of
var o = { a: a, b: b, c: c };
</pre>

<h3 id="배열_리터럴">배열 리터럴</h3>

<p>See also {{jsxref("Array")}} for more information.</p>

<pre class="brush: js notranslate">[1954, 1974, 1990, 2014]</pre>

<h3 id="문자열_리터럴">문자열 리터럴</h3>

<p>A string literal is zero or more Unicode code points enclosed in single or double quotes. Unicode code points may also be represented by an escape sequence. All code points may appear literally in a string literal except for these closing quote code points:</p>

<ul>
 <li>U+005C (backslash),</li>
 <li>U+000D &lt;CR&gt;,</li>
 <li>and U+000A &lt;LF&gt;.</li>
</ul>

<p>Prior to the <a href="https://github.com/tc39/proposal-json-superset">proposal to make all JSON text valid ECMA-262</a>, U+2028 &lt;LS&gt; and U+2029 &lt;PS&gt;, were also disallowed from appearing unescaped in string literals.</p>

<p>Any code points may appear in the form of an escape sequence. String literals evaluate to ECMAScript String values. When generating these String values Unicode code points are UTF-16 encoded.</p>

<pre class="brush: js notranslate">'foo'
"bar"</pre>

<h4 id="16진수_이스케이프_시퀀스">16진수 이스케이프 시퀀스</h4>

<p>Hexadecimal escape sequences consist of <code>\x</code> followed by exactly two hexadecimal digits representing a code unit or code point in the range 0x0000 to 0x00FF.</p>

<pre class="brush: js notranslate">'\xA9' // "©"
</pre>

<h4 id="유니코드_이스케이프_시퀀스">유니코드 이스케이프 시퀀스</h4>

<p>A Unicode escape sequence consists of exactly four hexadecimal digits following <code>\u</code>. It represents a code unit in the UTF-16 encoding. For code points U+0000 to U+FFFF, the code unit is equal to the code point. Code points U+10000 to U+10FFFF require two escape sequences representing the two code units (a surrogate pair) used to encode the character; the surrogate pair is distinct from the code point.</p>

<p>See also {{jsxref("String.fromCharCode()")}} and {{jsxref("String.prototype.charCodeAt()")}}.</p>

<pre class="brush: js notranslate">'\u00A9' // "©" (U+A9)</pre>

<h4 id="유니코드_코드_포인트_시퀀스">유니코드 코드 포인트 시퀀스</h4>

<p>A Unicode code point escape consists of <code>\u{</code>, followed by a code point in hexadecimal base, followed by <code>}</code>. The value of the hexadecimal digits must be in the range 0 and 0x10FFFF inclusive. Code points in the range U+10000 to U+10FFFF do not need to be represented as a surrogate pair. Code point escapes were added to JavaScript in ECMAScript 2015 (ES6).</p>

<p>See also {{jsxref("String.fromCodePoint()")}} and {{jsxref("String.prototype.codePointAt()")}}.</p>

<pre class="brush: js notranslate">'\u{2F804}' // CJK COMPATIBILITY IDEOGRAPH-2F804 (U+2F804)

// the same character represented as a surrogate pair
'\uD87E\uDC04'</pre>

<h3 id="정규_표현식_리터럴">정규 표현식 리터럴</h3>

<p>See also <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp"><code>RegExp</code></a> for more information.</p>

<pre class="brush: js notranslate">/ab+c/g

// An "empty" regular expression literal
// The empty non-capturing group is necessary
// to avoid ambiguity with single-line comments.
/(?:)/</pre>

<h3 id="템플릿_리터럴">템플릿 리터럴</h3>

<p>See also <a href="/en-US/docs/Web/JavaScript/Reference/template_strings">template strings</a> for more information.</p>

<pre class="brush: js notranslate">`string text`

`string text line 1
 string text line 2`

`string text ${expression} string text`

tag `string text ${expression} string text`</pre>

<h2 id="자동_세미콜론_삽입">자동 세미콜론 삽입</h2>

<p>Some <a href="/en-US/docs/Web/JavaScript/Reference/Statements">JavaScript statements</a> must be terminated with semicolons and are therefore affected by automatic semicolon insertion (ASI):</p>

<ul>
 <li>Empty statement</li>
 <li><code>let</code>, <code>const</code>, variable statement</li>
 <li><code>import</code>, <code>export</code>, module declaration</li>
 <li>Expression statement</li>
 <li><code>debugger</code></li>
 <li><code>continue</code>, <code>break</code>, <code>throw</code></li>
 <li><code>return</code></li>
</ul>

<p>The ECMAScript specification mentions<a href="https://tc39.github.io/ecma262/#sec-rules-of-automatic-semicolon-insertion"> three rules of semicolon insertion</a>.</p>

<p>1. A semicolon is inserted before, when a <a href="#Line_terminators">Line terminator</a> or "}" is encountered that is not allowed by the grammar.</p>

<pre class="brush: js notranslate">{ 1 2 } 3

// is transformed by ASI into

{ 1 2 ;} 3;</pre>

<p>2. A semicolon is inserted at the end, when the end of the input stream of tokens is detected and the parser is unable to parse the single input stream as a complete program.</p>

<p>Here <code>++</code> is not treated as a <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Increment">postfix operator</a> applying to variable <code>b</code>, because a line terminator occurs between <code>b</code> and <code>++</code>.</p>

<pre class="brush: js notranslate">a = b
++c

// is transformend by ASI into

a = b;
++c;
</pre>

<p>3. A semicolon is inserted at the end, when a statement with restricted productions in the grammar is followed by a line terminator. These statements with "no LineTerminator here" rules are:</p>

<ul>
 <li>PostfixExpressions (<code>++</code> and <code>--</code>)</li>
 <li><code>continue</code></li>
 <li><code>break</code></li>
 <li><code>return</code></li>
 <li><code>yield</code>, <code>yield*</code></li>
 <li><code>module</code></li>
</ul>

<pre class="brush: js notranslate">return
a + b

// is transformed by ASI into

return;
a + b;
</pre>

<h2 id="명세">명세</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('ES1')}}</td>
   <td>{{Spec2("ES1")}}</td>
   <td>Initial definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-7', 'Lexical Conventions')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-ecmascript-language-lexical-grammar', 'Lexical Grammar')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>Added: Binary and Octal Numeric literals, Unicode code point escapes, Templates</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-ecmascript-language-lexical-grammar', 'Lexical Grammar')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

<h2 id="브라우저_호환성">브라우저 호환성</h2>



<p>{{Compat("javascript.grammar")}}</p>

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

<ul>
 <li>{{jsxref("Boolean")}}</li>
 <li>{{jsxref("Number")}}</li>
 <li>{{jsxref("RegExp")}}</li>
 <li>{{jsxref("String")}}</li>
 <li><a href="http://whereswalden.com/2013/08/12/micro-feature-from-es6-now-in-firefox-aurora-and-nightly-binary-and-octal-numbers/">Jeff Walden: Binary and octal numbers</a></li>
 <li><a href="http://mathiasbynens.be/notes/javascript-escapes">Mathias Bynens: JavaScript character escape sequences</a></li>
</ul>