aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/javascript/reference/errors/delete_in_strict_mode/index.html
blob: 138384bcac3f56d146e69b22516713edd5e94d99 (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
---
title: >-
  SyntaxError: applying the 'delete' operator to an unqualified name is
  deprecated
slug: Web/JavaScript/Reference/Errors/Delete_in_strict_mode
tags:
  - 가비지 컬렉터
  - 구문 에러
  - 변수 삭제
  - 자바스크립트
translation_of: Web/JavaScript/Reference/Errors/Delete_in_strict_mode
---
<div>{{jsSidebar("Errors")}}</div>

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

<pre class="syntaxbox">SyntaxError: Calling delete on expression not allowed in strict mode (Edge)
SyntaxError: applying the 'delete' operator to an unqualified name is deprecated (Firefox)
SyntaxError: Delete of an unqualified identifier in strict mode. (Chrome)
</pre>

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

<p>엄격(Strict) 모드에서의 {{jsxref("SyntaxError")}}</p>

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

<p>자바스크립트에서 일반 변수는 <code><a href="/en-US/docs/Web/JavaScript/Reference/Operators/delete">delete</a></code> 연산자를 사용하여 삭제할 수 없습니다. 엄격 모드에서 변수를 삭제하는 접근은 허용되지 않으므로 에러가 발생합니다.</p>

<p><code>delete</code> 연산자는 오직 객체의 속성만을 삭제할 수 있습니다. 객체 속성은 설정할 수 있는 경우 "수식"될 수 있습니다.</p>

<p>일반적인 생각과 다르게 <code>delete</code> 연산자는 메모리 해제와 직접적인 연관이 없습니다. 메모리 관리는 참조가 깨짐에 따라 간접적으로 수행됩니다. 자세한 내용은 <a href="https://developer.mozilla.org/ko/docs/Web/JavaScript/Memory_Management">메모리 관리</a> 페이지와 <code><a href="/en-US/docs/Web/JavaScript/Reference/Operators/delete">delete</a></code> 연산자 페이지를 참조하십시오.</p>

<p>이 에러는 오직 <a href="https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Strict_mode">엄격 모드 코드</a>에서만 발생합니다. 엄격하지 않은 모드에서 해당 연산자는 단순히 <code>false</code> 를 반환합니다.</p>

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

<p>자바스크립트에서 일반 변수를 삭제하려고 하면 동작하지 않습니다. 그리고 엄격 모드에서는 에러가 발생합니다:</p>

<pre class="brush: js example-bad">'use strict';

var x;

// ...

delete x;

// SyntaxError: applying the 'delete' operator to an unqualified name
// is deprecated
</pre>

<p>변수의 내용을 비우려면 {{jsxref("null")}}을 설정하면 됩니다:</p>

<pre class="brush: js example-good">'use strict';

var x;

// ...

x = null;

// x는 가비지 컬렉터에 의해 메모리에서 해제됩니다
</pre>

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

<ul>
 <li><code><a href="/en-US/docs/Web/JavaScript/Reference/Operators/delete">delete</a></code></li>
 <li><a href="/en-US/docs/Web/JavaScript/Memory_Management">메모리 관리</a></li>
 <li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Cant_delete">TypeError: property "x" is non-configurable and can't be deleted</a></li>
</ul>