From da78a9e329e272dedb2400b79a3bdeebff387d47 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:17 -0500 Subject: initial commit --- .../reference/errors/bad_octal/index.html | 45 ++++++++ .../reference/errors/bad_radix/index.html | 57 ++++++++++ .../reference/errors/bad_regexp_flag/index.html | 107 +++++++++++++++++++ .../errors/bad_return_or_yield/index.html | 51 +++++++++ .../index.html | 56 ++++++++++ .../errors/delete_in_strict_mode/index.html | 71 +++++++++++++ .../index.html | 70 ++++++++++++ .../reference/errors/deprecated_octal/index.html | 64 +++++++++++ .../errors/identifier_after_number/index.html | 57 ++++++++++ .../reference/errors/illegal_character/index.html | 81 ++++++++++++++ .../ko/web/javascript/reference/errors/index.html | 12 +++ .../errors/invalid_array_length/index.html | 73 +++++++++++++ .../invalid_assignment_left-hand_side/index.html | 50 +++++++++ .../reference/errors/invalid_date/index.html | 50 +++++++++ .../errors/invalid_for-in_initializer/index.html | 75 +++++++++++++ .../errors/invalid_for-of_initializer/index.html | 64 +++++++++++ .../reference/errors/is_not_iterable/index.html | 106 ++++++++++++++++++ .../reference/errors/json_bad_parse/index.html | 105 ++++++++++++++++++ .../errors/malformed_formal_parameter/index.html | 57 ++++++++++ .../errors/missing_bracket_after_list/index.html | 56 ++++++++++ .../missing_colon_after_property_id/index.html | 78 ++++++++++++++ .../missing_curly_after_property_list/index.html | 47 ++++++++ .../errors/missing_initializer_in_const/index.html | 55 ++++++++++ .../missing_name_after_dot_operator/index.html | 63 +++++++++++ .../index.html | 38 +++++++ .../missing_parenthesis_after_condition/index.html | 65 ++++++++++++ .../missing_semicolon_before_statement/index.html | 63 +++++++++++ .../errors/more_arguments_needed/index.html | 45 ++++++++ .../errors/negative_repetition_count/index.html | 40 +++++++ .../reference/errors/no_variable_name/index.html | 79 ++++++++++++++ .../reference/errors/not_a_codepoint/index.html | 51 +++++++++ .../reference/errors/not_a_constructor/index.html | 91 ++++++++++++++++ .../reference/errors/not_defined/index.html | 66 ++++++++++++ .../reference/errors/precision_range/index.html | 92 ++++++++++++++++ .../errors/property_access_denied/index.html | 42 ++++++++ .../reference/errors/read-only/index.html | 77 ++++++++++++++ .../index.html | 83 +++++++++++++++ .../errors/reserved_identifier/index.html | 80 ++++++++++++++ .../errors/resulting_string_too_large/index.html | 46 ++++++++ .../errors/strict_non_simple_params/index.html | 107 +++++++++++++++++++ .../reference/errors/too_much_recursion/index.html | 50 +++++++++ .../reference/errors/undeclared_var/index.html | 62 +++++++++++ .../reference/errors/undefined_prop/index.html | 58 ++++++++++ .../reference/errors/unexpected_token/index.html | 49 +++++++++ .../reference/errors/unexpected_type/index.html | 67 ++++++++++++ .../errors/unnamed_function_statement/index.html | 118 +++++++++++++++++++++ 46 files changed, 3019 insertions(+) create mode 100644 files/ko/web/javascript/reference/errors/bad_octal/index.html create mode 100644 files/ko/web/javascript/reference/errors/bad_radix/index.html create mode 100644 files/ko/web/javascript/reference/errors/bad_regexp_flag/index.html create mode 100644 files/ko/web/javascript/reference/errors/bad_return_or_yield/index.html create mode 100644 files/ko/web/javascript/reference/errors/cant_access_lexical_declaration_before_init/index.html create mode 100644 files/ko/web/javascript/reference/errors/delete_in_strict_mode/index.html create mode 100644 files/ko/web/javascript/reference/errors/deprecated_caller_or_arguments_usage/index.html create mode 100644 files/ko/web/javascript/reference/errors/deprecated_octal/index.html create mode 100644 files/ko/web/javascript/reference/errors/identifier_after_number/index.html create mode 100644 files/ko/web/javascript/reference/errors/illegal_character/index.html create mode 100644 files/ko/web/javascript/reference/errors/index.html create mode 100644 files/ko/web/javascript/reference/errors/invalid_array_length/index.html create mode 100644 files/ko/web/javascript/reference/errors/invalid_assignment_left-hand_side/index.html create mode 100644 files/ko/web/javascript/reference/errors/invalid_date/index.html create mode 100644 files/ko/web/javascript/reference/errors/invalid_for-in_initializer/index.html create mode 100644 files/ko/web/javascript/reference/errors/invalid_for-of_initializer/index.html create mode 100644 files/ko/web/javascript/reference/errors/is_not_iterable/index.html create mode 100644 files/ko/web/javascript/reference/errors/json_bad_parse/index.html create mode 100644 files/ko/web/javascript/reference/errors/malformed_formal_parameter/index.html create mode 100644 files/ko/web/javascript/reference/errors/missing_bracket_after_list/index.html create mode 100644 files/ko/web/javascript/reference/errors/missing_colon_after_property_id/index.html create mode 100644 files/ko/web/javascript/reference/errors/missing_curly_after_property_list/index.html create mode 100644 files/ko/web/javascript/reference/errors/missing_initializer_in_const/index.html create mode 100644 files/ko/web/javascript/reference/errors/missing_name_after_dot_operator/index.html create mode 100644 files/ko/web/javascript/reference/errors/missing_parenthesis_after_argument_list/index.html create mode 100644 files/ko/web/javascript/reference/errors/missing_parenthesis_after_condition/index.html create mode 100644 files/ko/web/javascript/reference/errors/missing_semicolon_before_statement/index.html create mode 100644 files/ko/web/javascript/reference/errors/more_arguments_needed/index.html create mode 100644 files/ko/web/javascript/reference/errors/negative_repetition_count/index.html create mode 100644 files/ko/web/javascript/reference/errors/no_variable_name/index.html create mode 100644 files/ko/web/javascript/reference/errors/not_a_codepoint/index.html create mode 100644 files/ko/web/javascript/reference/errors/not_a_constructor/index.html create mode 100644 files/ko/web/javascript/reference/errors/not_defined/index.html create mode 100644 files/ko/web/javascript/reference/errors/precision_range/index.html create mode 100644 files/ko/web/javascript/reference/errors/property_access_denied/index.html create mode 100644 files/ko/web/javascript/reference/errors/read-only/index.html create mode 100644 files/ko/web/javascript/reference/errors/reduce_of_empty_array_with_no_initial_value/index.html create mode 100644 files/ko/web/javascript/reference/errors/reserved_identifier/index.html create mode 100644 files/ko/web/javascript/reference/errors/resulting_string_too_large/index.html create mode 100644 files/ko/web/javascript/reference/errors/strict_non_simple_params/index.html create mode 100644 files/ko/web/javascript/reference/errors/too_much_recursion/index.html create mode 100644 files/ko/web/javascript/reference/errors/undeclared_var/index.html create mode 100644 files/ko/web/javascript/reference/errors/undefined_prop/index.html create mode 100644 files/ko/web/javascript/reference/errors/unexpected_token/index.html create mode 100644 files/ko/web/javascript/reference/errors/unexpected_type/index.html create mode 100644 files/ko/web/javascript/reference/errors/unnamed_function_statement/index.html (limited to 'files/ko/web/javascript/reference/errors') diff --git a/files/ko/web/javascript/reference/errors/bad_octal/index.html b/files/ko/web/javascript/reference/errors/bad_octal/index.html new file mode 100644 index 0000000000..8a4590e668 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/bad_octal/index.html @@ -0,0 +1,45 @@ +--- +title: 'SyntaxError: "x" is not a legal ECMA-262 octal constant' +slug: Web/JavaScript/Reference/Errors/Bad_octal +translation_of: Web/JavaScript/Reference/Errors/Bad_octal +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
Warning: SyntaxError: 08 is not a legal ECMA-262 octal constant.
+Warning: SyntaxError: 09 is not a legal ECMA-262 octal constant.
+
+ +

에러 형식

+ +

{{jsxref("SyntaxError")}}엄격 모드(strict mode)에서만 경고 됨.

+ +

무엇이 잘못되었을까?

+ +

10진법의 리터럴은 0을 가장 앞 자리에 표시하고 뒤따라 다른 10진 숫자가 오게 할 수 있지만, 0으로 시작하여 그 뒤를 따르는 모든 숫자들이 8보다 작다면, 그 수는 8진수로 해석됩니다. 이런 경우에는 08 09는 허용되지 않기 때문에 JavaScript는 경고를 띄웁니다. 

+ +

8진 리터럴과 8진 escape sequence는 사라지고 추가적인 경고가 나타날 것임을 알아 두세요. ECMAScript 6와 그 이후 버전의 구문은, 맨 앞자리에 위치하는 0의 뒤에 소문자 또는 대문자의 라틴 문자 "O" 를 위치시키도록 합니다 (0o or 0O). 더 자세한 설명은 lexical grammar 페이지를 보세요.

+ +

+ +

유효하지 않은 8진수

+ +
08;
+09;
+// SyntaxError: 08 is not a legal ECMA-262 octal constant
+// SyntaxError: octal literals and octal escape sequences are deprecated
+ +

유효한 8진수

+ +

선두로 사용된 0의 뒤에는 문자 "o"가 오도록 한다. 

+ +
0O755;
+0o644;
+
+ +

참고

+ + diff --git a/files/ko/web/javascript/reference/errors/bad_radix/index.html b/files/ko/web/javascript/reference/errors/bad_radix/index.html new file mode 100644 index 0000000000..3ea98bf1eb --- /dev/null +++ b/files/ko/web/javascript/reference/errors/bad_radix/index.html @@ -0,0 +1,57 @@ +--- +title: 'RangeError: radix must be an integer' +slug: Web/JavaScript/Reference/Errors/Bad_radix +translation_of: Web/JavaScript/Reference/Errors/Bad_radix +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
RangeError: radix must be an integer at least 2 and no greater than 36 (Firefox)
+RangeError: toString() radix argument must be between 2 and 36 (Chrome)
+
+ +

에러 형식

+ +

{{jsxref("RangeError")}}

+ +

무엇이 잘못되었을까?

+ +

{{jsxref("Number.prototype.toString()")}} 메소드는 선택적 파라메터인 radix(기수:진수를 지정하는 값)와 함께 사용되어 왔습니다. 이 파라메터는 반드시 수의 값을 나타내는 진법의 2와 36 사이로 지정된 정수(숫자)여야 합니다. 

+ +

왜 36으로 제한이 되었을까요? radix는 digit(밑기수) 알파벳 글자로 사용되는 10보다는 큽니다. 그렇기 때문에, radix는 라틴 알파벳 26글자를 가졌을 때, 36보다 클 수 없습니다.  

+ +

보통 아래의 radix 중 하나를 사용하게 될 것입니다.

+ + + +

+ +

허용되지 않는 경우

+ +
(42).toString(0);
+(42).toString(1);
+(42).toString(37);
+(42).toString(150);
+//포맷팅하기 위해 string을 이런 식으로 사용할 수는 없습니다. :
+(12071989).toString("MM-dd-yyyy");
+
+ +

허용된 경우

+ +
(42).toString(2);     // "101010" (2진수)
+(13).toString(8);     // "15"     (8진수)
+(0x42).toString(10);  // "66"     (10진수)
+(100000).toString(16) // "186a0"  (16진수)
+
+ +

참조

+ + diff --git a/files/ko/web/javascript/reference/errors/bad_regexp_flag/index.html b/files/ko/web/javascript/reference/errors/bad_regexp_flag/index.html new file mode 100644 index 0000000000..2c8d12289d --- /dev/null +++ b/files/ko/web/javascript/reference/errors/bad_regexp_flag/index.html @@ -0,0 +1,107 @@ +--- +title: 'SyntaxError: invalid regular expression flag "x"' +slug: Web/JavaScript/Reference/Errors/Bad_regexp_flag +tags: + - 구문 에러 + - 자바스크립트 + - 정규식 + - 플래그 +translation_of: Web/JavaScript/Reference/Errors/Bad_regexp_flag +--- +
{{jsSidebar("Errors")}}
+ +

메세지

+ +
SyntaxError: Syntax error in regular expression (Edge)
+SyntaxError: invalid regular expression flag "x" (Firefox)
+SyntaxError: Invalid regular expression flags (Chrome)
+
+ +

에러 타입

+ +

{{jsxref("SyntaxError")}}

+ +

무엇이 잘못되었을까?

+ +

코드에 잘못된 정규 표현식 플래그가 있습니다. 슬래시로 묶인 패턴으로 구성되어 있는 정규 표현식 문자에서 플래그는 두 번째 플래그 뒤에 정의됩니다. 플래그는 또한 {{jsxref("RegExp")}} 객체의 생성자 함수에서도 정의될 수 있습니다(두 번째 매개변수). 정규 표현식 플래그는 따로 또는 순서에 상관 없이 같이 사용될 수 있지만 ECMAScript에는 오직 5개만 있습니다.

+ +

정규 표현식에 플래그를 포함시키려면 아래의 문법을 사용하세요:

+ +
var re = /pattern/flags;
+
+ +

또는

+ +
var re = new RegExp('pattern', 'flags');
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
정규 표현식 플래그
플래그설명
g전역 검색.
i대소문자 구별 없이 검색.
m여러 줄(Multi-line) 검색.
u유니코드; 패턴을 유니코드 코드 포인트의 나열로 취급.
y현재 위치에서 검색. ("sticky" 검색). {{jsxref("RegExp.sticky", "sticky")}} 참조.
+ +

예제

+ +

5개의 플래그만이 유효합니다.

+ +
/foo/bar;
+
+// SyntaxError: invalid regular expression flag "b"
+
+ +

정규 표현식을 만들려고 했나요? 두 개의 슬래시가 포함된 표현식은 정규 표현식 문자로 해석됩니다.

+ +
let obj = {
+  url: /docs/Web
+};
+
+// SyntaxError: invalid regular expression flag "W"
+
+ +

아니면 문자열로 만들려고 했나요? 작은 따옴표 또는 큰 따옴표를 추가하여 문자열을 만듭니다.

+ +
let obj = {
+  url: '/docs/Web'
+};
+ +

유효한 정규 표현식 플래그

+ +

자바스크립트에서 허용하는 5개의 유효한 정규 표현식 플래그를 위의 표에서 확인하세요.

+ +
/foo/g;
+/foo/gim;
+/foo/uy;
+
+ +

같이 보기

+ + diff --git a/files/ko/web/javascript/reference/errors/bad_return_or_yield/index.html b/files/ko/web/javascript/reference/errors/bad_return_or_yield/index.html new file mode 100644 index 0000000000..1239fa27f4 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/bad_return_or_yield/index.html @@ -0,0 +1,51 @@ +--- +title: 'SyntaxError: return not in function' +slug: Web/JavaScript/Reference/Errors/Bad_return_or_yield +translation_of: Web/JavaScript/Reference/Errors/Bad_return_or_yield +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
SyntaxError: return not in function
+SyntaxError: yield not in function
+
+ +

에러 타입

+ +

{{jsxref("SyntaxError")}}.

+ +

뭐가 잘못된 걸까요?

+ +

return 또는 yield 문장이 function 밖에서 호출되었기 때문입니다. 혹시 어딘가에 중괄호를 빠트리신 건 아닌가요? return 과 yield function 내에 있어야 합니다, 왜냐하면 이것들은 function의 실행 종료 (또는 일시정지 및 재개)를 의미하고 function 호출자에게 특정 값을 반환하기 위해 사용되기 때문입니다.

+ +

예제

+ +
var cheer = function(score) {
+  if (score === 147)
+    return 'Maximum!';
+  };
+  if (score > 100) {
+    return 'Century!';
+  }
+}
+
+// SyntaxError: return not in function
+ +

처음 볼 때는 중괄호가 제대로 있는 것처럼 보인다, 하지만 이 코드 조각에는 if 문장 다음에 중괄호가 하나 빠져 있다. 다음처럼 고쳐야 한다:

+ +
var cheer = function(score) {
+  if (score === 147) {
+    return 'Maximum!';
+  }
+  if (score > 100) {
+    return 'Century!';
+  }
+};
+ +

또 다른 내용

+ + diff --git a/files/ko/web/javascript/reference/errors/cant_access_lexical_declaration_before_init/index.html b/files/ko/web/javascript/reference/errors/cant_access_lexical_declaration_before_init/index.html new file mode 100644 index 0000000000..593e8cca13 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/cant_access_lexical_declaration_before_init/index.html @@ -0,0 +1,56 @@ +--- +title: 'ReferenceError: can''t access lexical declaration`X'' before initialization' +slug: Web/JavaScript/Reference/Errors/Cant_access_lexical_declaration_before_init +translation_of: Web/JavaScript/Reference/Errors/Cant_access_lexical_declaration_before_init +--- +
{{jsSidebar("Errors")}}
+ +

Message

+ +
ReferenceError: can't access lexical declaration `X' before initialization (Firefox)
+ReferenceError: 'x' is not defined (Chrome)
+
+ +

Error type

+ +

{{jsxref("ReferenceError")}}

+ +

무엇이 잘못 되었을까요?

+ +

변수가 초기화 되기 전에 엑세스가 되어버립니다. 이 문제는 let 또는 const 선언이 정의 되기 전에 엑세스되는 모든 block 문에서 발생합니다.

+ +

Examples

+ +

잘못된 경우

+ +

이 경우에 변수 "foo"는 let 을 사용하여 block 문에서 다시 선언됩니다.

+ +
function test() {
+  let foo = 33;
+  if (true) {
+    let foo = (foo + 55);
+    // ReferenceError: can't access lexical
+    // declaration `foo' before initialization
+  }
+}
+test();
+
+ +

올바른 경우

+ +

if 문에서 "foo"를 변경하려면 재 선언을 발생시키는 let 을 제거해야합니다.

+ +
function test(){
+   let foo = 33;
+   if (true) {
+      foo = (foo + 55);
+   }
+}
+test();
+
+ +

그밖에 볼 것

+ + diff --git a/files/ko/web/javascript/reference/errors/delete_in_strict_mode/index.html b/files/ko/web/javascript/reference/errors/delete_in_strict_mode/index.html new file mode 100644 index 0000000000..138384bcac --- /dev/null +++ b/files/ko/web/javascript/reference/errors/delete_in_strict_mode/index.html @@ -0,0 +1,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 +--- +
{{jsSidebar("Errors")}}
+ +

메세지

+ +
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)
+
+ +

에러 타입

+ +

엄격(Strict) 모드에서의 {{jsxref("SyntaxError")}}

+ +

무엇이 잘못되었을까?

+ +

자바스크립트에서 일반 변수는 delete 연산자를 사용하여 삭제할 수 없습니다. 엄격 모드에서 변수를 삭제하는 접근은 허용되지 않으므로 에러가 발생합니다.

+ +

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

+ +

일반적인 생각과 다르게 delete 연산자는 메모리 해제와 직접적인 연관이 없습니다. 메모리 관리는 참조가 깨짐에 따라 간접적으로 수행됩니다. 자세한 내용은 메모리 관리 페이지와 delete 연산자 페이지를 참조하십시오.

+ +

이 에러는 오직 엄격 모드 코드에서만 발생합니다. 엄격하지 않은 모드에서 해당 연산자는 단순히 false 를 반환합니다.

+ +

예제

+ +

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

+ +
'use strict';
+
+var x;
+
+// ...
+
+delete x;
+
+// SyntaxError: applying the 'delete' operator to an unqualified name
+// is deprecated
+
+ +

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

+ +
'use strict';
+
+var x;
+
+// ...
+
+x = null;
+
+// x는 가비지 컬렉터에 의해 메모리에서 해제됩니다
+
+ +

같이 보기

+ + diff --git a/files/ko/web/javascript/reference/errors/deprecated_caller_or_arguments_usage/index.html b/files/ko/web/javascript/reference/errors/deprecated_caller_or_arguments_usage/index.html new file mode 100644 index 0000000000..fc613db1d0 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/deprecated_caller_or_arguments_usage/index.html @@ -0,0 +1,70 @@ +--- +title: 'ReferenceError: deprecated caller or arguments usage' +slug: Web/JavaScript/Reference/Errors/Deprecated_caller_or_arguments_usage +translation_of: Web/JavaScript/Reference/Errors/Deprecated_caller_or_arguments_usage +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
Warning: ReferenceError: deprecated caller usage (Firefox)
+Warning: ReferenceError: deprecated arguments usage (Firefox)
+TypeError: 'callee' and 'caller' cannot be accessed in strict mode. (Safari)
+
+ +

에러 형식

+ +

엄격 모드에서만 {{jsxref("ReferenceError")}} 경고가 발생합니다. JavaScript 실행이 중단되지는 않을 것입니다.   

+ +

무엇이 잘못되었을까?

+ +

엄격모드에서, {{jsxref("Function.caller")}} 나 {{jsxref("Function.arguments")}} 속성이 사용되었고, 그러지 말아야 했습니다. 이 속성들은 사라지게 되었는데, 함수 호출자를 흘려보내거나, 비 표준이었으며, 최적화 하기 어렵고, 잠재적으로 퍼포먼스에 무리를 주었기 때문입니다.

+ +

+ +

function.caller or arguments.callee.caller

+ +

{{jsxref("Function.caller")}} 와 arguments.callee.caller 는 사라지게 되었습니다. (자세한 정보는 레퍼런스 문서를 확인해 보세요.)

+ +
"use strict";
+
+function myFunc() {
+  if (myFunc.caller == null) {
+    return 'The function was called from the top!';
+  } else {
+    return 'This function\'s caller was ' + myFunc.caller;
+  }
+}
+
+myFunc();
+// Warning: ReferenceError: deprecated caller usage
+// "The function was called from the top!"
+ +

Function.arguments

+ +

{{jsxref("Function.arguments")}} 는 사라졌습니다. (자세한 정보는 레퍼런스 문서를 확인해 주세요.) 

+ +
"use strict";
+
+function f(n) { g(n - 1); }
+
+function g(n) {
+  console.log('before: ' + g.arguments[0]);
+  if (n > 0) { f(n); }
+  console.log('after: ' + g.arguments[0]);
+}
+
+f(2);
+
+console.log('returned: ' + g.arguments);
+// Warning: ReferenceError: deprecated arguments usage
+
+ +

참조

+ + diff --git a/files/ko/web/javascript/reference/errors/deprecated_octal/index.html b/files/ko/web/javascript/reference/errors/deprecated_octal/index.html new file mode 100644 index 0000000000..55d85cf7eb --- /dev/null +++ b/files/ko/web/javascript/reference/errors/deprecated_octal/index.html @@ -0,0 +1,64 @@ +--- +title: 'SyntaxError: "0"-prefixed octal literals and octal escape seq. are deprecated' +slug: Web/JavaScript/Reference/Errors/Deprecated_octal +translation_of: Web/JavaScript/Reference/Errors/Deprecated_octal +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
SyntaxError: Octal numeric literals and escape characters not allowed in strict mode (Edge)
+SyntaxError:
+"0"-prefixed octal literals and octal escape sequences are deprecated;
+for octal literals use the "0o" prefix instead
+
+ +

에러 타입

+ +

{{jsxref("SyntaxError")}} strict mode 내에서만.

+ +

무엇이 잘 못 되었을까?

+ +

8진 리터럴과 8진수 이스케이프 시퀀스는 더 이상 사용하지 않으며, 엄격 모드(strict mode) 내에서는 {{jsxref("SyntaxError")}} 에러를 던질 것입니다. ECMAScript 2015와 이 후의 버전의 표준화된 구문은 0을 맨 앞자리에 두고 그 뒤를 대문자 또는 소문자의 라틴 문자 "O" 를 사용하도록 합니다. (0o 또는 0O)

+ +

예제

+ +

"0"이 접두인 8진 리터럴

+ +
"use strict";
+
+03;
+
+// SyntaxError: "0"-prefixed octal literals and octal escape sequences
+// are deprecated (0으로 시작하는 8진수와 8진 이스케이프 시퀀스는 더 이상 사용되지 않습니다. )
+
+ +

8진수 이스케이프 시퀀스

+ +
"use strict";
+
+"\251";
+
+// SyntaxError: "0"-prefixed octal literals and octal escape sequences
+// are deprecated (0으로 시작하는 8진수와 8진 이스케이프 시퀀스는 더 이상 사용되지 않습니다. )
+
+ +

유효한 8진 수들

+ +

0뒤에 "o" 또는 "O"를 사용합니다. :

+ +
0o3;
+
+ +

8진수 이스케이프 시퀀스 대신 16진수 이스케이프 시퀀스를 사용할 수도 있습니다. :

+ +
'\xA9';
+ +

See also

+ + diff --git a/files/ko/web/javascript/reference/errors/identifier_after_number/index.html b/files/ko/web/javascript/reference/errors/identifier_after_number/index.html new file mode 100644 index 0000000000..14e5b336c7 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/identifier_after_number/index.html @@ -0,0 +1,57 @@ +--- +title: 'SyntaxError: identifier starts immediately after numeric literal' +slug: Web/JavaScript/Reference/Errors/Identifier_after_number +tags: + - 구문 에러 + - 변수 이름 + - 식별자 + - 자바스크립트 +translation_of: Web/JavaScript/Reference/Errors/Identifier_after_number +--- +
{{JSSidebar("Errors")}}
+ +

메세지

+ +
SyntaxError: Unexpected identifier after numeric literal (Edge)
+SyntaxError: identifier starts immediately after numeric literal (Firefox)
+SyntaxError: Unexpected number (Chrome)
+
+ +

에러 타입

+ +

{{jsxref("SyntaxError")}}

+ +

무엇이 잘못되었을까?

+ +

{{Glossary("식별자", "식별자")}}라고 불리는 변수의 이름은 반드시 지켜야 하는 특정 규칙을 따라야 합니다.

+ +

자바스크립트의 식별자는 반드시 문자, 언더스코어(_), 또는 달러 표시($)로 시작돼야 합니다. 숫자로 시작될 수 없습니다. 글자 뒤에만 숫자(0-9)가 올 수 있습니다.

+ +

예제

+ +

숫자로 시작하는 변수 이름

+ +

자바스크립트에서 변수 이름은 숫자로 시작될 수 없습니다. 아래 예제는 에러가 발생합니다:

+ +
var 1life = 'foo';
+// SyntaxError: identifier starts immediately after numeric literal
+
+var foo = 1life;
+// SyntaxError: identifier starts immediately after numeric literal
+
+alert(1.foo);
+// SyntaxError: identifier starts immediately after numeric literal
+
+ +

숫자가 뒤에 오도록 변수 이름을 변경해야 합니다.

+ +
var life1 = 'foo';
+var foo = life1;
+
+ +

같이 보기

+ + diff --git a/files/ko/web/javascript/reference/errors/illegal_character/index.html b/files/ko/web/javascript/reference/errors/illegal_character/index.html new file mode 100644 index 0000000000..b3cd3a9750 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/illegal_character/index.html @@ -0,0 +1,81 @@ +--- +title: 'SyntaxError: illegal character' +slug: Web/JavaScript/Reference/Errors/Illegal_character +tags: + - ZWSP + - 구문 에러 + - 자바스크립트 + - 폭 없는 공백 +translation_of: Web/JavaScript/Reference/Errors/Illegal_character +--- +

{{jsSidebar("Errors")}}

+ +

메세지

+ +
SyntaxError: Invalid character (Edge)
+SyntaxError: illegal character (Firefox)
+SyntaxError: Invalid or unexpected token (Chrome)
+
+ +

에러 타입

+ +

{{jsxref("SyntaxError")}}

+ +

무엇이 잘못되었을까?

+ +

코드에 해당 구문에 맞지 않거나 예기치 않은 토큰이 있습니다. 마이너스 기호( - )와 대시() 또는 따옴표( " )와 비표준 따옴표() 등이 잘못 사용된 경우에 대해 문법 체크를 해주는 편집기를 사용하여 코드를 주의 깊게 확인해야 합니다.

+ +

예제

+ +

잘못 사용된 문자

+ +

일부 문자들은 비슷하게 보이지만 파서가 코드 해석을 실패하게 만듭니다. 유명한 예로 따옴표, 마이너스 또는 세미콜론(greek questionmark (U+37e)과 동일하게 보입니다)이 있습니다.

+ +
“This looks like a string”;  // SyntaxError: illegal character
+                             // 비슷해 보이지만 “와 ”는 "이 아닙니다
+
+42 – 13;                     // SyntaxError: illegal character
+                             // 비슷해 보이지만 –은 -이 아닙니다
+
+var foo = 'bar';             // SyntaxError: illegal character
+                             // 비슷해 보이지만 <37e>은 ;이 아닙니다
+
+ +

아래 예제는 정상적으로 동작합니다:

+ +
"This is actually a string";
+42 - 13;
+var foo = 'bar';
+
+ +

일부 편집기와 IDE는 문제가 있는 부분을 알려주거나 적어도 강조 표시를 해주지만 전부는 아닙니다. 이런 에러가 발생했을 때 무엇이 문제인지 찾을 수 없는 경우, 문제가 있는 줄을 지우고 다시 작성하는 것 가장 좋습니다.

+ +

문자 빠트리기

+ +

앞이나 뒤에 오는 문자를 잊어버리기 쉽습니다.

+ +
var colors = ['#000', #333', '#666'];
+// SyntaxError: illegal character
+
+ +

 '#333'에 빠진 작은따옴표를 추가합니다.

+ +
var colors = ['#000', '#333', '#666'];
+ +

숨겨진 문자

+ +

다른 곳에서 코드를 복사하여 붙여넣은 경우 잘못된 문자가 포함돼 있을 수 있습니다. 주의하세요!

+ +
var foo = 'bar';​
+// SyntaxError: illegal character
+
+ +

Vim과 같은 편집기에서 아래 코드를 체크하면 폭 없는 공백(zero-width space (ZWSP) (U+200B)) 문자가 있는 것을 확인할 수 있습니다.

+ +
var foo = 'bar';​<200b>
+ +

같이 보기

+ + diff --git a/files/ko/web/javascript/reference/errors/index.html b/files/ko/web/javascript/reference/errors/index.html new file mode 100644 index 0000000000..79e24cc575 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/index.html @@ -0,0 +1,12 @@ +--- +title: JavaScript error reference +slug: Web/JavaScript/Reference/Errors +tags: + - JavaScript +translation_of: Web/JavaScript/Reference/Errors +--- +

{{jsSidebar("Errors")}}

+ +

오류, 사방에 오류.

+ +

{{ListSubPages("/ko/docs/Web/JavaScript/Reference/Errors")}}

diff --git a/files/ko/web/javascript/reference/errors/invalid_array_length/index.html b/files/ko/web/javascript/reference/errors/invalid_array_length/index.html new file mode 100644 index 0000000000..6ddeb58f06 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/invalid_array_length/index.html @@ -0,0 +1,73 @@ +--- +title: 'RangeError: invalid array length' +slug: Web/JavaScript/Reference/Errors/Invalid_array_length +translation_of: Web/JavaScript/Reference/Errors/Invalid_array_length +--- +
{{jsSidebar("Errors")}}
+ +

메세지

+ +
RangeError: invalid array length (Firefox)
+RangeError: Invalid array length (Chrome)
+RangeError: Invalid array buffer length (Chrome)
+
+ +

에러 형식

+ +

{{jsxref("RangeError")}}

+ +

무엇이 잘못 된 것일까?

+ +

다음과 같은 원인 때문이다:

+ + + +

Array와 ArrayBuffer의 길이에 제한을 둔 이유는, Array나 ArrayBuffer의 length 속성은 사인되지 않은(unsigned) 32 비트 정수로 반영되기 때문이다.Array나 ArrayBuffer는 오직 0 ~ 232-1 사이의 값만을 저장할 수 있다.

+ +

Array의 length로 해석되는 첫번째 argument로서 문자열 표기를 통해 contructor를 사용하여 Array를 생성할 수 있다.

+ +

다른 방법으로는, length 속성을 설정하기 전에 length의 길이에 제한을 두거나, constructor의 aurgment로서 사용할 수 있다.

+ +

예제

+ +

잘못된 예제

+ +
new Array(Math.pow(2, 40))
+new Array(-1)
+new ArrayBuffer(Math.pow(2, 32))
+new ArrayBuffer(-1)
+
+let a = [];
+a.length = a.length - 1;         // set -1 to the length property
+
+let b = new Array(Math.pow(2, 32) - 1);
+b.length = b.length + 1;         // set 2^32 to the length property
+
+ +

올바른 예제

+ +
[ Math.pow(2, 40) ]                     // [ 1099511627776 ]
+[ -1 ]                                  // [ -1 ]
+new ArrayBuffer(Math.pow(2, 32) - 1)
+new ArrayBuffer(0)
+
+let a = [];
+a.length = Math.max(0, a.length - 1);
+
+let b = new Array(Math.pow(2, 32) - 1);
+b.length = Math.min(0xffffffff, b.length + 1);
+
+// 0xffffffff is the hexadecimal notation for 2^32 - 1
+// which can also be written as (-1 >>> 0)
+
+ +

 

+ + diff --git a/files/ko/web/javascript/reference/errors/invalid_assignment_left-hand_side/index.html b/files/ko/web/javascript/reference/errors/invalid_assignment_left-hand_side/index.html new file mode 100644 index 0000000000..7a7acf3ca2 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/invalid_assignment_left-hand_side/index.html @@ -0,0 +1,50 @@ +--- +title: 'ReferenceError: invalid assignment left-hand side' +slug: Web/JavaScript/Reference/Errors/Invalid_assignment_left-hand_side +translation_of: Web/JavaScript/Reference/Errors/Invalid_assignment_left-hand_side +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
ReferenceError: invalid assignment left-hand side
+
+ +

에러 타입

+ +

{{jsxref("ReferenceError")}}.

+ +

무엇이 잘못되었을까?

+ +

예상치 못한 할당이 일어났습니다. 이것은 할당 연산자(assignment operator)와 비교 연산자(comparison operator) 간의 불일치로 인한 것일 겁니다.  예를 들면, "=" 부호는 값을 변수에 할당합니다.  "==" 나  "==="는 값을 비교하는 연산을 합니다.

+ +

+ +
if (Math.PI = 3 || Math.PI = 4) {
+  console.log('no way!');
+}
+// ReferenceError: invalid assignment left-hand side
+
+var str = 'Hello, '
++= 'is it me '
++= 'you\'re looking for?';
+// ReferenceError: invalid assignment left-hand side
+
+ +

if 구문에서, 비교 연산자 ("==")로 비교하려 할 때, 문자열의 연속적인 결합의 경우에는, 플러스("+") 연산자가 필요합니다.

+ +
if (Math.PI == 3 || Math.PI == 4) {
+  console.log('no way!');
+}
+
+var str = 'Hello, '
++ 'from the '
++ 'other side!';
+
+ +

참조

+ + diff --git a/files/ko/web/javascript/reference/errors/invalid_date/index.html b/files/ko/web/javascript/reference/errors/invalid_date/index.html new file mode 100644 index 0000000000..32cf041e7e --- /dev/null +++ b/files/ko/web/javascript/reference/errors/invalid_date/index.html @@ -0,0 +1,50 @@ +--- +title: 'RangeError: invalid date' +slug: Web/JavaScript/Reference/Errors/Invalid_date +translation_of: Web/JavaScript/Reference/Errors/Invalid_date +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
RangeError: invalid date (Firefox)
+RangeError: invalid time value (Chrome)
+RangeError: Provided date is not in valid range (Chrome)
+
+ +

에러 종류

+ +

{{jsxref("RangeError")}}

+ +

무엇이 잘못 된 걸까?

+ +

유효하지 않은 String이 {{jsxref("Date")}} 나 {{jsxref("Date.parse()")}}에 입력되었습니다.

+ +

예시

+ +

올바르지 않은 사용 예시

+ +

인식 할 수 없는 string이나 잘못된 요소 값을 포함하는 ISO 형식의 날짜 string은 일반적으로 {{jsxref ( "NaN")}}을 반환합니다. 그러나 구현 방식에 따라 ISO 형식 string을 따르지 않는 경우 RangeError: invalid date가 표시 될 수 있습니다. Firefox의 경우:

+ +
new Date('foo-bar 2014');
+new Date('2014-25-23').toISOString();
+new Date('foo-bar 2014').toString();
+
+ +

그러나 이 경우, Firefox에서는 {{jsxref("NaN")}} 을 반환합니다:

+ +
Date.parse('foo-bar 2014'); // NaN
+ +

더 자세한 사항은  {{jsxref("Date.parse()")}} 문서를 참고하세요.

+ +

올바른 사용 예시

+ +
new Date('05 October 2011 14:48 UTC');
+ +

더 보기

+ + diff --git a/files/ko/web/javascript/reference/errors/invalid_for-in_initializer/index.html b/files/ko/web/javascript/reference/errors/invalid_for-in_initializer/index.html new file mode 100644 index 0000000000..7dd5e15a9a --- /dev/null +++ b/files/ko/web/javascript/reference/errors/invalid_for-in_initializer/index.html @@ -0,0 +1,75 @@ +--- +title: 'SyntaxError: for-in loop head declarations may not have initializers' +slug: Web/JavaScript/Reference/Errors/Invalid_for-in_initializer +tags: + - for...in 구문 + - 구문 에러 + - 배열 반복 + - 자바스크립트 + - 초기화 +translation_of: Web/JavaScript/Reference/Errors/Invalid_for-in_initializer +--- +
{{jsSidebar("Errors")}}
+ +

메세지

+ +
SyntaxError: for-in loop head declarations cannot have an initializer (Edge)
+SyntaxError: for-in loop head declarations may not have initializers (Firefox)
+SyntaxError: for-in loop variable declaration may not have an initializer. (Chrome)
+
+ +

에러 타입

+ +

엄격(Strict) 모드에서의 {{jsxref("SyntaxError")}}.

+ +

무엇이 잘못되었을까?

+ +

for...in 반복문의 선언부에 초기화 구문이 포함되어 있습니다. 즉, |for (var i = 0 in obj)| 구문을 통해 변수가 정의되고 값이 할당된 것을 말합니다. 비엄격 모드(non-strict) 모드에서는 이 초기화 구문이 무시되어 |for (var i in obj)| 처럼 동작합니다. 하지만 엄격 모드에서는 SyntaxError 가 발생합니다.

+ +

예제

+ +

이 예제는 SyntaxError를 발생시킵니다.

+ +
"use strict";
+
+var obj = {a: 1, b: 2, c: 3 };
+
+for (var i = 0 in obj) {
+  console.log(obj[i]);
+}
+
+// SyntaxError: for-in loop head declarations may not have initializers
+
+ +

올바른 for-in 반복문

+ +

for-in 반복문의 선언부에서 초기화 구문(i = 0)을 삭제합니다.

+ +
"use strict";
+
+var obj = {a: 1, b: 2, c: 3 };
+
+for (var i in obj) {
+  console.log(obj[i]);
+}
+
+ +

배열 반복

+ +

for...in 반복문은 배열을 반복하는데에는 사용하지 않습니다. 배열({{jsxref("Array")}})을 반복하기 위해 for-in 반복문 대신에 for 반복문을 사용하려고 한 적이 있습니까? for 반복문은 선언부에서 초기화도 할 수 있습니다:

+ +
var arr = [ "a", "b", "c" ]
+
+for (var i = 2; i < arr.length; i++) {
+  console.log(arr[i]);
+}
+
+// "c"
+ +

같이 보기

+ + diff --git a/files/ko/web/javascript/reference/errors/invalid_for-of_initializer/index.html b/files/ko/web/javascript/reference/errors/invalid_for-of_initializer/index.html new file mode 100644 index 0000000000..0e60e242e8 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/invalid_for-of_initializer/index.html @@ -0,0 +1,64 @@ +--- +title: >- + SyntaxError: a declaration in the head of a for-of loop can't have an + initializer +slug: Web/JavaScript/Reference/Errors/Invalid_for-of_initializer +tags: + - For문 초기화 + - 구문 에러 + - 반복문 + - 자바스크립트 +translation_of: Web/JavaScript/Reference/Errors/Invalid_for-of_initializer +--- +
{{jsSidebar("Errors")}}
+ +

메세지

+ +
SyntaxError: for-of loop head declarations cannot have an initializer (Edge)
+SyntaxError: a declaration in the head of a for-of loop can't have an initializer (Firefox)
+SyntaxError: for-of loop variable declaration may not have an initializer. (Chrome)
+
+ +

에러 타입

+ +

{{jsxref("SyntaxError")}}

+ +

무엇이 잘못되었을까?

+ +

for...of 반복문의 식이 초기화 구문을 포함한 것이 문제입니다. 즉, |for (var i = 0 of iterable)| 구문을 통해 변수가 정의되고 값이 할당된 것을 말합니다. 이 구문은 for-of 반복문에서 허용되지 않습니다. 이 경우 초기화를 할 수 있는 for 반복문이 필요합니다.

+ +

예제

+ +

잘못된 for-of 반복문

+ +
let iterable = [10, 20, 30];
+
+for (let value = 50 of iterable) {
+  console.log(value);
+}
+
+// SyntaxError: a declaration in the head of a for-of loop can't
+// have an initializer
+ +

올바른 for-of 반복문

+ +

for-of 반복문에서 초기화 구문(value = 50)을 삭제해야 합니다. 50을 더하고 싶다면 다음 예제와 같이 반복문 안에 추가할 수 있습니다.

+ +
let iterable = [10, 20, 30];
+
+for (let value of iterable) {
+  value += 50;
+  console.log(value);
+}
+// 60
+// 70
+// 80
+
+ +

같이 보기

+ + diff --git a/files/ko/web/javascript/reference/errors/is_not_iterable/index.html b/files/ko/web/javascript/reference/errors/is_not_iterable/index.html new file mode 100644 index 0000000000..8e00501d54 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/is_not_iterable/index.html @@ -0,0 +1,106 @@ +--- +title: 'TypeError: ''x'' is not iterable' +slug: Web/JavaScript/Reference/Errors/is_not_iterable +tags: + - JavaScript + - 레퍼런스 + - 에러 + - 타입에러 +translation_of: Web/JavaScript/Reference/Errors/is_not_iterable +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
TypeError: 'x' is not iterable (Firefox, Chrome)
+TypeError: 'x' is not a function or its return value is not iterable (Chrome)
+
+ +

에러 타입

+ +

{{jsxref("TypeError")}}

+ +

무엇이 문제인가요?

+ +

{{jsxref("Promise.all")}} 또는 {{jsxref("TypedArray.from")}} 과 같은 함수의 아규먼트 또는 for…of 의 right hand-side 로 주어진 값이 iterable 객체가 아닙니다. iterable 은 {{jsxref("Array")}}, {{jsxref("String")}} 또는 {{jsxref("Map")}}, 생성자 결과, 또는 iterable protocol 구현 객체와 같은 내장 iterable 타입이 될 수 있습니다.

+ +

예제

+ +

모든 객체 프로퍼티 iterating

+ +

JavaScript 에서 iterable protocol 을 구현하지 않은 {{jsxref("Object")}} 는 iterable 이 아닙니다.
+ 그러므로, 객체의 프로퍼티를 반복하기 위해 for…of 를 사용하면 안됩니다.

+ +
var obj = { 'France': 'Paris', 'England': 'London' };
+for (let p of obj) { // TypeError: obj is not iterable
+    // …
+}
+
+ +

객체의 모든 항목 또는 프로퍼티를 반복하려면 대신 {{jsxref("Object.keys")}} 또는 {{jsxref("Object.entries")}} 를 사용해야 합니다.

+ +
var obj = { 'France': 'Paris', 'England': 'London' };
+// 모든 프로퍼티 이름을 iterate:
+for (let country of Object.keys(obj)) {
+    var capital = obj[country];
+    console.log(country, capital);
+}
+
+for (const [country, capital] of Object.entries(obj))
+    console.log(country, capital);
+
+
+
+ +

이 유즈 케이스에 대한 다른 옵션은 {{jsxref("Map")}} 을 사용하는 것입니다.

+ +
var map = new Map;
+map.set('France', 'Paris');
+map.set('England', 'London');
+// 모든 프로퍼티 이름 iterate
+for (let country of map.keys()) {
+    let capital = map[country];
+    console.log(country, capital);
+}
+
+for (let capital of map.values())
+    console.log(capital);
+
+for (const [country, capital] of map.entries())
+    console.log(country, capital);
+
+ +

Generator iterating

+ +

Generators 는 iterable 객체를 생성하기 위해 호출하는 함수입니다.

+ +
function* generate(a, b) {
+  yield a;
+  yield b;
+}
+
+for (let x of generate) // TypeError: generate is not iterable
+    console.log(x);
+
+ +

generator 가 호출되지 않으면, generator 에 해당하는 {{jsxref("Function")}} 객체를 호출할수는 있지만 interable 하지는 않습니다. generator 호출은 generator 실행동안 yield 된 모든 값을 iterate 하는 iterable 객체를 생성합니다.

+ +
function* generate(a, b) {
+    yield a;
+    yield b;
+}
+
+for (let x of generate(1,2))
+    console.log(x);
+
+ +

함께 보기

+ + diff --git a/files/ko/web/javascript/reference/errors/json_bad_parse/index.html b/files/ko/web/javascript/reference/errors/json_bad_parse/index.html new file mode 100644 index 0000000000..c73b082dbb --- /dev/null +++ b/files/ko/web/javascript/reference/errors/json_bad_parse/index.html @@ -0,0 +1,105 @@ +--- +title: 'SyntaxError: JSON.parse: bad parsing' +slug: Web/JavaScript/Reference/Errors/JSON_bad_parse +translation_of: Web/JavaScript/Reference/Errors/JSON_bad_parse +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
SyntaxError: JSON.parse: unterminated string literal
+SyntaxError: JSON.parse: bad control character in string literal
+SyntaxError: JSON.parse: bad character in string literal
+SyntaxError: JSON.parse: bad Unicode escape
+SyntaxError: JSON.parse: bad escape character
+SyntaxError: JSON.parse: unterminated string
+SyntaxError: JSON.parse: no number after minus sign
+SyntaxError: JSON.parse: unexpected non-digit
+SyntaxError: JSON.parse: missing digits after decimal point
+SyntaxError: JSON.parse: unterminated fractional number
+SyntaxError: JSON.parse: missing digits after exponent indicator
+SyntaxError: JSON.parse: missing digits after exponent sign
+SyntaxError: JSON.parse: exponent part is missing a number
+SyntaxError: JSON.parse: unexpected end of data
+SyntaxError: JSON.parse: unexpected keyword
+SyntaxError: JSON.parse: unexpected character
+SyntaxError: JSON.parse: end of data while reading object contents
+SyntaxError: JSON.parse: expected property name or '}'
+SyntaxError: JSON.parse: end of data when ',' or ']' was expected
+SyntaxError: JSON.parse: expected ',' or ']' after array element
+SyntaxError: JSON.parse: end of data when property name was expected
+SyntaxError: JSON.parse: expected double-quoted property name
+SyntaxError: JSON.parse: end of data after property name when ':' was expected
+SyntaxError: JSON.parse: expected ':' after property name in object
+SyntaxError: JSON.parse: end of data after property value in object
+SyntaxError: JSON.parse: expected ',' or '}' after property value in object
+SyntaxError: JSON.parse: expected ',' or '}' after property-value pair in object literal
+SyntaxError: JSON.parse: property names must be double-quoted strings
+SyntaxError: JSON.parse: expected property name or '}'
+SyntaxError: JSON.parse: unexpected character
+SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data
+
+ +

에러 타입

+ +

{{jsxref("SyntaxError")}}

+ +

뭐가 잘못됬나요?

+ +

{{jsxref("JSON.parse()")}} 는 문자열을 JSON으로 파싱한다. 이 문자열은 유효한 JSON 형태의 문자열이어야 하며, 유효하지 않을 경우 에러가 발생한다.

+ +

예제

+ +

JSON.parse() 는 여분의 콤마를 허용하지 않는다.

+ +

다음 두 줄은 SyntaxError를 발생시킨다:

+ +
JSON.parse('[1, 2, 3, 4,]');
+JSON.parse('{"foo": 1,}');
+// SyntaxError JSON.parse: unexpected character
+// at line 1 column 14 of the JSON data
+
+ +

끝에 오는 콤마를 제거하면 정확하게 JSON으로 파싱한다:

+ +
JSON.parse('[1, 2, 3, 4]');
+JSON.parse('{"foo": 1}');
+ +

프로퍼티 이름은 반드시 쌍따옴표로 표현해야 한다.

+ +

'foo'처럼 프로퍼티를 작은 따옴표로 감싸서는 안된다.

+ +
JSON.parse("{'foo': 1}");
+// SyntaxError: JSON.parse: expected property name or '}'
+// at line 1 column 2 of the JSON data
+ +

대신에 "foo" 처럼 써야 한다:

+ +
JSON.parse('{"foo": 1}');
+ +

리딩 제로와 십진 소수점

+ +

01 처럼 리딩제로를 사용할 수 없고, 십진 소수점 뒤에는 최소한 하나의 숫자는 등장해야 한다.

+ +
JSON.parse('{"foo": 01}');
+// SyntaxError: JSON.parse: expected ',' or '}' after property value
+// in object at line 1 column 2 of the JSON data
+
+JSON.parse('{"foo": 1.}');
+// SyntaxError: JSON.parse: unterminated fractional number
+// at line 1 column 2 of the JSON data
+
+ +

대신에 리딩제로를 없애고 1 이라고 쓰고, 십진 소수점 뒤에는 반드시 하나 이상의 숫자를 적도록 한다:

+ +
JSON.parse('{"foo": 1}');
+JSON.parse('{"foo": 1.0}');
+
+ +

또다른 내용

+ + diff --git a/files/ko/web/javascript/reference/errors/malformed_formal_parameter/index.html b/files/ko/web/javascript/reference/errors/malformed_formal_parameter/index.html new file mode 100644 index 0000000000..e258ba49e6 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/malformed_formal_parameter/index.html @@ -0,0 +1,57 @@ +--- +title: 'SyntaxError: Malformed formal parameter' +slug: Web/JavaScript/Reference/Errors/Malformed_formal_parameter +translation_of: Web/JavaScript/Reference/Errors/Malformed_formal_parameter +--- +
{{jsSidebar("Errors")}}
+ +

Message

+ +
SyntaxError: malformed formal parameter (Firefox)
+
+ +

Error type

+ +

{{jsxref("SyntaxError")}}

+ +

무엇이 잘못 되었을까요?

+ +

코드에는 최소한 두 개의 인수가 전달 된 Function() 생성자가 있습니다. 마지막 인수는 작성중인 새 함수의 소스코드 입니다.  나머지는 모두 새 함수의 인수 목록을 구성합니다.

+ +

인수 목록이 어딘가 잘못되었습니다. 아마도 실수로 인수 이름으로 if 또는 var와 같은 키워드를 선택했거나 인수 목록에 갈곳 잃은 구두점이 있을 수 있습니다. 또는 실수로 숫자나 개체와 같은 잘못된 값을 전달한 것일 수 있습니다.

+ +

그래, 내 문제가 해결됐어. 근데 왜 말 안해줬어?

+ +

틀림 없이 오류 메세지의 표현은 다소 이상한 부분이 있습니다. "공식 매개 변수"는 "함수 인수"를 말하는 좋은 방법입니다. 우리는 "잘못된 형식의 단어를 사용했다"라고 표현 합니다.

+ +

Examples

+ +

Invalid cases

+ +
var f = Function('x y', 'return x + y;');
+// SyntaxError (missing a comma)
+
+var f = Function('x,', 'return x;');
+// SyntaxError (extraneous comma)
+
+var f = Function(37, "alert('OK')");
+// SyntaxError (numbers can't be argument names)
+
+ +

Valid cases

+ +
var f = Function('x, y', 'return x + y;');  // correctly punctuated
+
+var f = Function('x', 'return x;');
+
+// if you can, avoid using Function - this is much faster
+var f = function(x) { return x; };
+
+ +

See also

+ + diff --git a/files/ko/web/javascript/reference/errors/missing_bracket_after_list/index.html b/files/ko/web/javascript/reference/errors/missing_bracket_after_list/index.html new file mode 100644 index 0000000000..b9149ac159 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/missing_bracket_after_list/index.html @@ -0,0 +1,56 @@ +--- +title: 'SyntaxError: missing ] after element list' +slug: Web/JavaScript/Reference/Errors/Missing_bracket_after_list +tags: + - 구문 에러 + - 배열 초기자 + - 자바스크립트 +translation_of: Web/JavaScript/Reference/Errors/Missing_bracket_after_list +--- +
{{jsSidebar("Errors")}}
+ +

메세지

+ +
SyntaxError: missing ] after element list
+
+ +

에러 타입

+ +

{{jsxref("SyntaxError")}}.

+ +

무엇이 잘못되었을까?

+ +

배열 초기자 구문에 오류가 있습니다. 닫는 대괄호("]") 또는 콤마(",")가 빠진 것 같습니다.

+ +

예제

+ +

완성되지 않은 배열 초기자

+ +
var list = [1, 2,
+
+var instruments = [
+  'Ukulele',
+  'Guitar',
+  'Piano'
+};
+
+var data = [{foo: 'bar'} {bar: 'foo'}];
+
+ +

바르게 고치면:

+ +
var list = [1, 2];
+
+var instruments = [
+ 'Ukulele',
+ 'Guitar',
+ 'Piano'
+];
+
+var data = [{foo: 'bar'}, {bar: 'foo'}];
+ +

같이 보기

+ + diff --git a/files/ko/web/javascript/reference/errors/missing_colon_after_property_id/index.html b/files/ko/web/javascript/reference/errors/missing_colon_after_property_id/index.html new file mode 100644 index 0000000000..4fe7865664 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/missing_colon_after_property_id/index.html @@ -0,0 +1,78 @@ +--- +title: 'SyntaxError: missing : after property id' +slug: Web/JavaScript/Reference/Errors/Missing_colon_after_property_id +tags: + - 객체 초기자 + - 계산된 속성 + - 구문 에러 + - 자바스크립트 +translation_of: Web/JavaScript/Reference/Errors/Missing_colon_after_property_id +--- +
{{jsSidebar("Errors")}}
+ +

메세지

+ +
SyntaxError: Expected ':' (Edge)
+SyntaxError: missing : after property id (Firefox)
+
+ +

에러 타입

+ +

{{jsxref("SyntaxError")}}

+ +

무엇이 문제일까?

+ +

객체 초기자 구문으로 객체를 만들 때 콜론(:)은 객체의 속성을 키와 값으로 분리합니다.

+ +
var obj = { propertyKey: 'value' };
+
+ +

예제

+ +

콜론 vs. 등호

+ +

객체 초기자 구문에는 등호를 사용할 수 없으므로 아래 예제는 실패합니다.

+ +
var obj = { propertyKey = 'value' };
+// SyntaxError: missing : after property id
+
+ +

콜론을 사용하거나 객체를 생성한 뒤에 대괄호를 사용하여 새로운 속성을 할당하는 것이 바릅니다.

+ +
var obj = { propertyKey: 'value' };
+
+// 또는
+
+var obj = { };
+obj['propertyKey'] = 'value';
+
+ +

빈 속성

+ +

아래와 같이 빈 속성을 만들 수 없습니다:

+ +
var obj = { propertyKey; };
+// SyntaxError: missing : after property id
+
+ +

만약 값 없이 속성을 정의해야 한다면 값으로 {{jsxref("null")}}을 지정할 수 있습니다.

+ +
var obj = { propertyKey: null };
+ +

계산된 속성

+ +

식으로 속성의 키를 만드는 경우 대괄호를 사용해야 합니다. 그렇지 않으면 속성 이름에 계산된 값을 사용할 수 없습니다:

+ +
var obj = { 'b'+'ar': 'foo' };
+// SyntaxError: missing : after property id
+
+ +

식에 대괄호를 넣으세요 []:

+ +
var obj = { ['b'+'ar']: 'foo' };
+ +

같이 보기

+ + diff --git a/files/ko/web/javascript/reference/errors/missing_curly_after_property_list/index.html b/files/ko/web/javascript/reference/errors/missing_curly_after_property_list/index.html new file mode 100644 index 0000000000..8e0abf94db --- /dev/null +++ b/files/ko/web/javascript/reference/errors/missing_curly_after_property_list/index.html @@ -0,0 +1,47 @@ +--- +title: 'SyntaxError: missing } after property list' +slug: Web/JavaScript/Reference/Errors/Missing_curly_after_property_list +translation_of: Web/JavaScript/Reference/Errors/Missing_curly_after_property_list +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
SyntaxError: missing } after property list
+
+ +

에러 유형

+ +

{{jsxref("SyntaxError")}}

+ +

무엇이 잘못 된 걸까?

+ +

객체를 초기화 하는 부분 어딘가에 구문에 실수가 있습니다. 실제로 빠진 중괄호 일 수도 있지만, 누락 된 쉼표 일 수도 있습니다. 또한 닫는 중괄호나 괄호가 올바른 순서인지 확인하세요. 코드를 들여쓰기하거나 서식을 지정하면 좀 더 보기 쉽습니다.

+ +

예시

+ +

쉼표를 까먹은 경우

+ +

종종 객체 초기화 과정에서 쉼표를 빠트리는 경우가 있습니다:

+ +
var obj = {
+  a: 1,
+  b: { myProp: 2 }
+  c: 3
+};
+
+ +

올바른 예시는 다음과 같습니다:

+ +
var obj = {
+  a: 1,
+  b: { myProp: 2 },
+  c: 3
+};
+
+ +

더 보기

+ + diff --git a/files/ko/web/javascript/reference/errors/missing_initializer_in_const/index.html b/files/ko/web/javascript/reference/errors/missing_initializer_in_const/index.html new file mode 100644 index 0000000000..be116cf3a4 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/missing_initializer_in_const/index.html @@ -0,0 +1,55 @@ +--- +title: 'SyntaxError: missing = in const declaration' +slug: Web/JavaScript/Reference/Errors/Missing_initializer_in_const +translation_of: Web/JavaScript/Reference/Errors/Missing_initializer_in_const +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
SyntaxError: Const must be initalized (Edge)
+SyntaxError: missing = in const declaration (Firefox)
+SyntaxError: Missing initializer in const declaration (Chrome)
+
+ +

에러 유형

+ +

{{jsxref("SyntaxError")}}

+ +

무엇이 잘못되었나요?

+ +

상수는 일반적인 실행 중에 프로그램에 의해 변경될 수 없는 값입니다. 상수는 재할당되거나 재선언될 수 없습니다. 자바스크립트에서 상수는 const 키워드를 사용해 선언됩니다. 상수는 이니셜라이저가 필요합니다. 다시말해, 한 문장 안에 선언과 동시에 초기화가 이루어져야 합니다 (따라서 추후 수정 불가).

+ +

예제

+ +

const 이니셜라이저가 빠진 경우

+ +

var 또는 let과 달리, const 선언에서는 반드시 값을 정의해야 합니다.

+ +
const COLUMNS;
+// SyntaxError: missing = in const declaration
+ +

에러 수정

+ +

해당 에러를 수정하기 위해서 여러가지 방법이 존재합니다. 문제 상황에서 상수를 사용해 무엇을 하려 했는지 확인해보세요.

+ +

상수 값 추가

+ +

선언과 같은 문장에 상수 값을 정의합니다.

+ +
const COLUMNS = 80;
+ +

const, letvar?

+ +

상수를 선언할 목적이 아니었다면 const를 사용하지 마세요. let 키워드를 이용한 블록범위 변수, 또는 var 키워드를 이용한 전역 변수를 사용할 수 있습니다. 두 가지 경우 모두 초기값을 요구하지 않습니다.

+ +
let columns;
+
+ +

같이 보기

+ + diff --git a/files/ko/web/javascript/reference/errors/missing_name_after_dot_operator/index.html b/files/ko/web/javascript/reference/errors/missing_name_after_dot_operator/index.html new file mode 100644 index 0000000000..a549e48e51 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/missing_name_after_dot_operator/index.html @@ -0,0 +1,63 @@ +--- +title: 'SyntaxError: missing name after . operator' +slug: Web/JavaScript/Reference/Errors/Missing_name_after_dot_operator +translation_of: Web/JavaScript/Reference/Errors/Missing_name_after_dot_operator +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
SyntaxError: missing name after . operator
+
+ +

에러 타입

+ +

{{jsxref("SyntaxError")}}

+ +

무엇이 잘 못 되었을까?

+ +

점 연산자 (.)는 프로퍼티 접근을 위해 사용합니다. 접근해야 하는 프로퍼티 명은 제대로 명시 해야 합니다. 연산 프로퍼티에 접근하려면, 점 연산자를 사용하지 않고 대괄호를 사용하는 것으로 프로퍼티 접근 방식을 바꿔야 합니다. 이런 방식들이 표현식의 계산을 수행시켜줄 것입니다. 아마 당신은 연결을 하려고 했을 것입니다. 이 경우에는 더하기 연산자(+)가 필요합니다. 아래의 예제를 봐주세요. 

+ +

예제

+ +

프로퍼티 접근

+ +

JavaScript 프로퍼티 접근자는 점(.) 또는 대괄호([]) 중 하나만 사용한다. 대괄호는 연산 프로퍼티에 접근을 허용합니다.   

+ +
var obj = { foo: { bar: "baz", bar2: "baz2" } };
+var i = 2;
+
+obj.[foo].[bar]
+// SyntaxError: missing name after . operator
+
+obj.foo."bar"+i;
+// SyntaxError: missing name after . operator
+
+ +

이 코드를 고치려면, 오브젝트에 이런 식으로 접근해야 합니다.:

+ +
obj.foo.bar; // "baz"
+// 또는 대신에
+obj["foo"]["bar"]; // "baz"
+
+// 연산 프로퍼티는 대괄호가 필요합니다.
+obj.foo["bar" + i]; // "baz2"
+
+ +

프로퍼티 접근 vs. 연결

+ +

다른 프로그램 언어를 사용하다 왔다면 ( {{Glossary("PHP")}} 같은), 점 연산자(.)와 연결 연산자(+)를 혼동해서 쓰기가 더 쉬울 것입니다.

+ +
console.log("Hello" . "world");
+
+// SyntaxError: missing name after . operator
+ +

대신에 결합을 위해서는 더하기 표식을 사용해야 합니다.:

+ +
console.log("Hello" + "World");
+ +

참조

+ + diff --git a/files/ko/web/javascript/reference/errors/missing_parenthesis_after_argument_list/index.html b/files/ko/web/javascript/reference/errors/missing_parenthesis_after_argument_list/index.html new file mode 100644 index 0000000000..1f28ac1104 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/missing_parenthesis_after_argument_list/index.html @@ -0,0 +1,38 @@ +--- +title: 'SyntaxError: missing ) after argument list' +slug: Web/JavaScript/Reference/Errors/Missing_parenthesis_after_argument_list +translation_of: Web/JavaScript/Reference/Errors/Missing_parenthesis_after_argument_list +--- +
{{jsSidebar("Errors")}}
+ +

Message

+ +
SyntaxError: missing ) after argument list
+
+ +

Error type

+ +

{{jsxref("SyntaxError")}}.

+ +

What went wrong?

+ +

function을 호출하는 방식에 에러가 있는 것입니다. 맞춤법, 연산자 누락 또는 이스케이프 처리를 하지 않는 문자열과 같은 것으로 발생될 수 있습니다.

+ +

Examples

+ +

문자열을 합치는 "+" 연산자가 없기 때문에, Javascript는 log function에 대한 인수를 "PI: "로 인식을 합니다. 이 경우, 닫침 괄호가 누락된 것으로 인식을 합니다.

+ +
console.log('PI: ' Math.PI);
+// SyntaxError: missing ) after argument list
+
+ +

You can correct the log call by adding the "+" operator:

+ +
console.log('PI: ' + Math.PI);
+// "PI: 3.141592653589793"
+ +

See also

+ + diff --git a/files/ko/web/javascript/reference/errors/missing_parenthesis_after_condition/index.html b/files/ko/web/javascript/reference/errors/missing_parenthesis_after_condition/index.html new file mode 100644 index 0000000000..cd7b368aa4 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/missing_parenthesis_after_condition/index.html @@ -0,0 +1,65 @@ +--- +title: 'SyntaxError: missing ) after condition' +slug: Web/JavaScript/Reference/Errors/Missing_parenthesis_after_condition +translation_of: Web/JavaScript/Reference/Errors/Missing_parenthesis_after_condition +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
SyntaxError: missing ) after condition
+
+ +

에러 유형

+ +

{{jsxref("SyntaxError")}}

+ +

무엇이 잘못 된 걸까?

+ +

if조건문에 에러가 있습니다. 어떠한 프로그래밍 언어에서든 코드는 입력값에 따라 의사를 결정하고 행동을 수행해야합니다. 지정된 조건이 true이면 if 문이 명령문을 실행합니다. 자바스크립트에서는 이 조건이 if문 다음의 괄호에 있어야 합니다. 다음은 그 예시입니다.

+ +
if (condition) {
+  // do something if the condition is true
+}
+ +

예시

+ +

실수가 있을 수 있으니, 모든 괄호를 주의깊게 확인하세요.

+ +
if (3 > Math.PI {
+  console.log("wait what?");
+}
+
+// SyntaxError: missing ) after condition
+
+ +

이 코드를 고치기 위해선, 조건문을 괄호로 닫아야 합니다.

+ +
if (3 > Math.PI) {
+  console.log("wait what?");
+}
+ +

다른 프로그래밍 언어를 배운 경우, 자바스크립트에서는 다르게 쓰이거나, 쓰이지 않는 키워드를 사용하기 쉽습니다.

+ +
if (done is true) {
+ console.log("we are done!");
+}
+
+// SyntaxError: missing ) after condition
+
+ +

이 경우 올바른 비교연산자를 사용해야 합니다. 그 예시로:

+ +
if (done === true) {
+ console.log("we are done!");
+}
+ +

더 보기

+ + diff --git a/files/ko/web/javascript/reference/errors/missing_semicolon_before_statement/index.html b/files/ko/web/javascript/reference/errors/missing_semicolon_before_statement/index.html new file mode 100644 index 0000000000..ec3334b52f --- /dev/null +++ b/files/ko/web/javascript/reference/errors/missing_semicolon_before_statement/index.html @@ -0,0 +1,63 @@ +--- +title: 'SyntaxError: missing ; before statement' +slug: Web/JavaScript/Reference/Errors/Missing_semicolon_before_statement +translation_of: Web/JavaScript/Reference/Errors/Missing_semicolon_before_statement +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
SyntaxError: missing ; before statement
+
+ +

오류 타입

+ +

{{jsxref("SyntaxError")}}.

+ +

무엇이 잘 못 되었나?

+ +

어딘가에 세미 콜론(;)이 빠져 있습니다.  JavaScript 구문은 반드시 세미 콜론으로 끝나야 합니다. 일부는 자동 세미콜론 삽입 (automatic semicolon insertion (ASI))의 영향을 받습니다. 그러나 이 경우에는 직접 세미 콜론을 써주어야 합니다. 그래야 JavaScript가 올바르게 해석 될 수 있기 때문입니다.

+ +

그러나, 가끔, 이 오류는 또 다른 오류의 결과로도 나타날 수도 있습니다. 문자열을 escape 문자로 적절히 처리해 주지 않았을 때, 또는 var 키워드를 잘 못 사용했을 때와 같은 경우 입니다. 또한 어딘가에 너무 많은 괄호 기호를 사용했을 것입니다. 이 오류가 발생했을 때에는 문법을 신중히 검토해야 합니다. 

+ +

예제

+ +

Escape 처리되지 않은 문자열

+ +

이 오류는 문자열을 escape 처리 하지 않았을 때, JavaScript 엔진이 문자열 끝을 미리 예측하여 발생합니다. 예를 들자면 아래와 같습니다. :

+ +
var foo = 'Tom's bar';
+// SyntaxError: missing ; before statement
+ +

문자열을 묶어줄 때 쌍 따옴표를 사용하거나, 역슬래시를 이용해서 홑따옴표를 사용 할 수 있습니다. :

+ +
var foo = "Tom's bar";
+var foo = 'Tom\'s bar';
+
+ +

var와 함께 선언하는 것

+ +

이미 var 선언된 object나 array의 요소를 새로 선언 할 수 없습니다.

+ +
var obj = {};
+var obj.foo = 'hi'; // SyntaxError missing ; before statement
+
+var array = [];
+var array[0] = 'there'; // SyntaxError missing ; before statement
+
+ +

대신에, var  키워드를 생략하고 정의합니다. :

+ +
var obj = {};
+obj.foo = 'hi';
+
+var array = [];
+array[0] = 'there';
+
+ +

참조 문서

+ + diff --git a/files/ko/web/javascript/reference/errors/more_arguments_needed/index.html b/files/ko/web/javascript/reference/errors/more_arguments_needed/index.html new file mode 100644 index 0000000000..41137d2f63 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/more_arguments_needed/index.html @@ -0,0 +1,45 @@ +--- +title: 'TypeError: More arguments needed' +slug: Web/JavaScript/Reference/Errors/More_arguments_needed +translation_of: Web/JavaScript/Reference/Errors/More_arguments_needed +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
TypeError: argument is not an Object and is not null (Edge)
+TypeError: Object.create requires at least 1 argument, but only 0 were passed
+TypeError: Object.setPrototypeOf requires at least 2 arguments, but only 0 were passed
+TypeError: Object.defineProperties requires at least 1 argument, but only 0 were passed
+
+ +

에러 타입

+ +

{{jsxref("TypeError")}}.

+ +

무엇이 잘 못 되었을까?

+ +

함수 호출 시 에러가 있습니다. 더 많은 인수가 주어져야 합니다.

+ +

예제

+ +

{{jsxref("Object.create()")}} 메서드는 적어도 1개의 인자가 필요하며, {{jsxref("Object.setPrototypeOf()")}} 메서드는 적어도 2개의 인자가 필요합니다.:

+ +
var obj = Object.create();
+// TypeError: Object.create requires at least 1 argument, but only 0 were passed
+
+var obj = Object.setPrototypeOf({});
+// TypeError: Object.setPrototypeOf requires at least 2 arguments, but only 1 were passed
+
+ +

예를 들면, 이렇게 프로토 타입으로  {{jsxref("null")}}를 세팅해서 고칠 수 있습니다.:

+ +
var obj = Object.create(null);
+
+var obj = Object.setPrototypeOf({}, null);
+ +

참조

+ + diff --git a/files/ko/web/javascript/reference/errors/negative_repetition_count/index.html b/files/ko/web/javascript/reference/errors/negative_repetition_count/index.html new file mode 100644 index 0000000000..b2437c9ad8 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/negative_repetition_count/index.html @@ -0,0 +1,40 @@ +--- +title: 'RangeError: repeat count must be non-negative' +slug: Web/JavaScript/Reference/Errors/Negative_repetition_count +translation_of: Web/JavaScript/Reference/Errors/Negative_repetition_count +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
RangeError: repeat count must be non-negative (Firefox)
+RangeError: Invalid count value (Chrome)
+
+ +

에러 형식

+ +

{{jsxref("RangeError")}}

+ +

무엇이 잘못되었을까?

+ +

{{jsxref("String.prototype.repeat()")}} 메소드가 사용되었습니다. 이 메소드는 문자열이 반복되는 수를 예측하는 카운트 파라메터를 가지고 있었습니다. 이 파라메터는 0보다 크고, 양의 {{jsxref("Infinity")}} 보다는 작으며, 음수는 될수 없습니다. 이 범위는 이렇게 표현 될 수 있습니다. : [0, +∞)

+ +

+ +

허용되지 않는 경우

+ +
'abc'.repeat(-1); // RangeError 
+ +

허용되는 경우

+ +
'abc'.repeat(0);    // ''
+'abc'.repeat(1);    // 'abc'
+'abc'.repeat(2);    // 'abcabc'
+'abc'.repeat(3.5);  // 'abcabcabc' (수는 정수로 변환될 것입니다.)
+
+ +

참조

+ + diff --git a/files/ko/web/javascript/reference/errors/no_variable_name/index.html b/files/ko/web/javascript/reference/errors/no_variable_name/index.html new file mode 100644 index 0000000000..e9d6ec6ee7 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/no_variable_name/index.html @@ -0,0 +1,79 @@ +--- +title: 'SyntaxError: missing variable name' +slug: Web/JavaScript/Reference/Errors/No_variable_name +translation_of: Web/JavaScript/Reference/Errors/No_variable_name +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
SyntaxError: missing variable name (Firefox)
+SyntaxError: Unexpected token = (Chrome)
+ +

에러 타입

+ +

{{jsxref("SyntaxError")}}

+ +

무엇이 잘 못 되었을까?

+ +

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

+ +

예제

+ +

이름을 잃은 변수

+ +
var = "foo";
+
+ +

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

+ +
var ohGodWhy = "foo";
+ +

예약어는 변수명이 될 수 없어요

+ +

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

+ +
var debugger = "whoop";
+// SyntaxError: missing variable name
+
+ +

여러 변수를 선언하기

+ +

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

+ +
var x, y = "foo",
+var x, = "foo"
+
+var first = document.getElementById('one'),
+var second = document.getElementById('two'),
+
+// SyntaxError: missing variable name
+
+ +

올바르게 수정한 버전:

+ +
var x, y = "foo";
+var x = "foo";
+
+var first = document.getElementById('one');
+var second = document.getElementById('two');
+ +

배열

+ +

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

+ +
var arr = 1,2,3,4,5;
+// SyntaxError: missing variable name
+
+ +

이렇게 해야 맞습니다:

+ +
var arr = [1,2,3,4,5];
+ +

더 보기

+ + diff --git a/files/ko/web/javascript/reference/errors/not_a_codepoint/index.html b/files/ko/web/javascript/reference/errors/not_a_codepoint/index.html new file mode 100644 index 0000000000..782cea10f2 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/not_a_codepoint/index.html @@ -0,0 +1,51 @@ +--- +title: 'RangeError: argument is not a valid code point' +slug: Web/JavaScript/Reference/Errors/Not_a_codepoint +translation_of: Web/JavaScript/Reference/Errors/Not_a_codepoint +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
RangeError: {0} is not a valid code point (Firefox)
+RangeError: Invalid code point {0} (Chrome)
+
+ +

에러 형식

+ +

{{jsxref("RangeError")}}

+ +

무엇이 잘못되었을까?

+ +

{{jsxref("String.fromCodePoint()")}} 메소드는 유효한 코드 포인트(code point)만을 받아들입니다.

+ +

code point는 유니코드의 코드 스페이스 값으로, 0부터 0x10FFFF까지의 정수 범위입니다.

+ +

{{jsxref("NaN")}}을 사용하는 값, 음수 (-1),  정수가 아닌 수(3.14), 또는 0x10FFFF (1114111) 보다 큰 값은 이 함수에 적용될 수 없습니다.

+ +

+ +

유효하지 않은 경우

+ +
String.fromCodePoint('_');      // RangeError
+String.fromCodePoint(Infinity); // RangeError
+String.fromCodePoint(-1);       // RangeError
+String.fromCodePoint(3.14);     // RangeError
+String.fromCodePoint(3e-2);     // RangeError
+String.fromCodePoint(NaN);      // RangeError
+ +

유효한 경우

+ +
String.fromCodePoint(42);       // "*"
+String.fromCodePoint(65, 90);   // "AZ"
+String.fromCodePoint(0x404);    // "\u0404"
+String.fromCodePoint(0x2F804);  // "\uD87E\uDC04"
+String.fromCodePoint(194564);   // "\uD87E\uDC04"
+String.fromCodePoint(0x1D306, 0x61, 0x1D307) // "\uD834\uDF06a\uD834\uDF07"
+
+ +

참조

+ + diff --git a/files/ko/web/javascript/reference/errors/not_a_constructor/index.html b/files/ko/web/javascript/reference/errors/not_a_constructor/index.html new file mode 100644 index 0000000000..80bc235779 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/not_a_constructor/index.html @@ -0,0 +1,91 @@ +--- +title: 'TypeError: "x" is not a constructor' +slug: Web/JavaScript/Reference/Errors/Not_a_constructor +translation_of: Web/JavaScript/Reference/Errors/Not_a_constructor +--- +
{{jsSidebar("Errors")}}
+ +

메세지

+ +
TypeError: "x" is not a constructor
+
+TypeError: Math is not a constructor
+TypeError: JSON is not a constructor
+TypeError: Symbol is not a constructor
+TypeError: Reflect is not a constructor
+TypeError: Intl is not a constructor
+TypeError: SIMD is not a constructor
+TypeError: Atomics is not a constructor
+
+ +

오류 유형

+ +

{{jsxref("TypeError")}}

+ +

뭐가 잘못된 거죠?

+ +

객체 혹은 변수를 생성자로 사용하려고 했습니다, 하지만 객체(혹은 변수)가 생성자가 아닙니다. 생성자가 무엇인지에 대한 자세한 정보는 {{Glossary("constructor")}} 혹은 new operator 를 참조하시기 바랍니다.

+ +

{{jsxref("String")}} 혹은 {{jsxref("Array")}}와 같이 new,를 사용하여 생성할 수 있는 전역 객체들이 있습니다. 하지만 일부 전역 객체들은 그렇지 않고 속성과 메서드가 정적입니다. 다음의 자바스크립트 표준 내장 객체들은 생성자가 아닙니다: {{jsxref("Math")}}, {{jsxref("JSON")}}, {{jsxref("Symbol")}}, {{jsxref("Reflect")}}, {{jsxref("Intl")}}, {{jsxref("SIMD")}}, {{jsxref("Atomics")}}.

+ +

Generator functions 또한 생성자로 사용될 수 없습니다.

+ +

예시

+ +

유효하지 않은 경우

+ +
var Car = 1;
+new Car();
+// TypeError: Car is not a constructor
+
+new Math();
+// TypeError: Math is not a constructor
+
+new Symbol();
+// TypeError: Symbol is not a constructor
+
+function* f() {};
+var obj = new f;
+// TypeError: f is not a constructor
+
+ +

car 생성자

+ +

자동차(car) 객체를 만들고자 한다고 가정합니다. 이 객체의 타입을 car라 하고 make, model, and year 세 개의 프로퍼티를 갖습니다. 이를 위해 다음과 같은 함수를 작성할 것입니다:

+ +
function Car(make, model, year) {
+  this.make = make;
+  this.model = model;
+  this.year = year;
+}
+
+ +

이제 다음과 같이 mycar 라 불리는 객체를 생성할 수 있습니다:

+ +
var mycar = new Car('Eagle', 'Talon TSi', 1993);
+ +

프라미스 이용

+ +

즉시 실행되는 프라미스를 반환하는 경우에는 새로운 Promise(...)를 생성할 필요가 없습니다.

+ +

아래는 올바른 방법이 아닙니다(프라미스 생성자가 제대로 호출되고 있지 않습니다). TypeError: this is not a constructor 예외를 던지게 됩니다:

+ +
return new Promise.resolve(true);
+
+ +

대신, Promise.resolve() 혹은 Promise.reject() 정적 메서드를 사용하십시오:

+ +
// This is legal, but unnecessarily long:
+return new Promise((resolve, reject) => { resolve(true); })
+
+// Instead, return the static method:
+return Promise.resolve(true);
+return Promise.reject(false);
+
+ +

같이 보기

+ + diff --git a/files/ko/web/javascript/reference/errors/not_defined/index.html b/files/ko/web/javascript/reference/errors/not_defined/index.html new file mode 100644 index 0000000000..6b403dd848 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/not_defined/index.html @@ -0,0 +1,66 @@ +--- +title: 'ReferenceError: "x" is not defined' +slug: Web/JavaScript/Reference/Errors/Not_defined +translation_of: Web/JavaScript/Reference/Errors/Not_defined +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
ReferenceError: "x" is not defined
+
+ +

에러 타입

+ +

{{jsxref("ReferenceError")}}.

+ +

무엇이 잘못되었을까?

+ +

존재하지 않는 변수를 참조하는 곳이 있습니다. 이 변수는 선언되어야 합니다. 또는, 현재 스크립트나 {{Glossary("scope")}} 에서 사용이 가능하도록 해야합니다.

+ +
+

Note: 라이브러리(예를 들면 jQuery와 같은)의 로딩은, 반드시 코드에서  "$"와 같은 라이브러리 변수에 접근하기 이전에 수행되어야 합니다. 라이브러리를 로딩하는 {{HTMLElement("script")}} 태그가 그 변수를 사용하는 코드보다 앞에 위치하도록 하세요.

+
+ +

+ +

선언되지 않은 변수

+ +
foo.substring(1); // ReferenceError: foo is not defined
+
+ +

"foo" 변수는 어디에도 선언되지 않았습니다. {{jsxref("String.prototype.substring()")}} 메소드가 작동하도록 하기 위해서는 문자열을 필요로 합니다.

+ +
var foo = "bar";
+foo.substring(1); // "ar"
+ +

잘못된 스코프

+ +

변수는 현재의 실행 흐름 내에서 이용 가능해야합니다. 함수 내부에 정의된 변수는 다른 외부의 함수에서는 접근할 수 없습니다. 그 때문에, 변수는 함수의 스코프 내부에서만 정의 됩니다.

+ +
function numbers () {
+  var num1 = 2,
+      num2 = 3;
+  return num1 + num2;
+}
+
+console.log(num1); // ReferenceError: num1 is not defined
+ +

그러나, 함수는 모든 변수와 정의된 스코프 안에 정의된 함수에 접근할 수 있습니다. 따라서, 전역으로 정의된 함수는 전역에 정의된 모든 변수에도 접근할 수 있습니다.

+ +
var num1 = 2,
+    num2 = 3;
+
+function numbers () {
+  return num1 + num2;
+}
+
+console.log(num1); // 2
+ +

참조

+ + diff --git a/files/ko/web/javascript/reference/errors/precision_range/index.html b/files/ko/web/javascript/reference/errors/precision_range/index.html new file mode 100644 index 0000000000..43ab7392e4 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/precision_range/index.html @@ -0,0 +1,92 @@ +--- +title: 'RangeError: precision is out of range' +slug: Web/JavaScript/Reference/Errors/Precision_range +translation_of: Web/JavaScript/Reference/Errors/Precision_range +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
RangeError: precision {0} out of range (Firefox)
+RangeError: toExponential() argument must be between 0 and 20 (Chrome)
+RangeError: toFixed() digits argument must be between 0 and 20 (Chrome)
+RangeError: toPrecision() argument must be between 1 and 21 (Chrome)
+
+ +

에러 형식

+ +

{{jsxref("RangeError")}}

+ +

무엇이 잘못되었을까?

+ +

아래의 메소드들 중 하나에서,  실행 인자(argument)가 정확도의 범위를 벗어났습니다. :

+ + + +

이 메소드들에게 허용된 범위는 0부터 20 (또는 21)까지 입니다. 하지만, ECMAScript 스펙은 아래의 범위까지 확장하여 허용하고 있습니다.

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
MethodFirefox (SpiderMonkey)Chrome, Opera (V8)
{{jsxref("Number.prototype.toExponential()")}}0 부터 1000 부터 20
{{jsxref("Number.prototype.toFixed()")}}-20 부터 1000 부터 20
{{jsxref("Number.prototype.toPrecision()")}}1 부터 1001 부터 21
+ +

+ +

유효하지 않은 경우

+ +
77.1234.toExponential(-1);  // RangeError
+77.1234.toExponential(101); // RangeError
+
+2.34.toFixed(-100);         // RangeError
+2.34.toFixed(1001);         // RangeError
+
+1234.5.toPrecision(-1);     // RangeError
+1234.5.toPrecision(101);    // RangeError
+
+ +

유효한 경우

+ +
77.1234.toExponential(4); // 7.7123e+1
+77.1234.toExponential(2); // 7.71e+1
+
+2.34.toFixed(1); // 2.3
+2.35.toFixed(1); // 2.4 (note that it rounds up in this case)
+
+5.123456.toPrecision(5); // 5.1235
+5.123456.toPrecision(2); // 5.1
+5.123456.toPrecision(1); // 5
+
+ +

참조

+ + diff --git a/files/ko/web/javascript/reference/errors/property_access_denied/index.html b/files/ko/web/javascript/reference/errors/property_access_denied/index.html new file mode 100644 index 0000000000..2468d0221a --- /dev/null +++ b/files/ko/web/javascript/reference/errors/property_access_denied/index.html @@ -0,0 +1,42 @@ +--- +title: 'Error: Permission denied to access property "x"' +slug: Web/JavaScript/Reference/Errors/Property_access_denied +translation_of: Web/JavaScript/Reference/Errors/Property_access_denied +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
Error: Permission denied to access property "x"
+
+ +

에러 형식

+ +

{{jsxref("Error")}}.

+ +

무엇이 잘못되었을까?

+ +

접근이 허가되지 않은 객체에 접근하기 위한 시도가 있었습니다. 아마 동일 출처 정책(same-origin policy)을 침해하여 다른 도메인으로부터 로드된 {{HTMLElement("iframe")}} 엘리먼트에 대한 것이었을 겁니다.

+ +

+ +
<!DOCTYPE html>
+<html>
+  <head>
+    <iframe id="myframe" src="http://www1.w3c-test.org/common/blank.html"></iframe>
+    <script>
+      onload = function() {
+        console.log(frames[0].document);
+        // Error: Permission denied to access property "document"
+      }
+    </script>
+  </head>
+  <body></body>
+</html>
+ +

참조

+ + diff --git a/files/ko/web/javascript/reference/errors/read-only/index.html b/files/ko/web/javascript/reference/errors/read-only/index.html new file mode 100644 index 0000000000..7260fd71f8 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/read-only/index.html @@ -0,0 +1,77 @@ +--- +title: 'TypeError: "x" is read-only' +slug: Web/JavaScript/Reference/Errors/Read-only +translation_of: Web/JavaScript/Reference/Errors/Read-only +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
TypeError: "x" is read-only (Firefox)
+TypeError: 0 is read-only (Firefox)
+TypeError: Cannot assign to read only property 'x' of #<Object> (Chrome)
+TypeError: Cannot assign to read only property '0' of [object Array] (Chrome)
+
+ +

에러 유형

+ +

{{jsxref("TypeError")}}

+ +

무엇이 잘못 된 걸까?

+ +

전역변수 또는 객체 프로퍼티가 읽기 전용으로 할당된 경우입니다.(엄밀히 따지자면 쓰기가 불가능한 데이터 속성입니다.)

+ +

이 에러는 엄격모드에서만 등장합니다.  엄격하지 않은 모드에서는 읽기전용 속성은 묵시적으로 무시됩니다.

+ +

예시

+ +

적절하지 않은 예

+ +

읽기 전용 속성은 아주 흔한 것은 아니지만, {{jsxref("Object.defineProperty()")}} 나 {{jsxref("Object.freeze()")}} 를 이용해 만들어 질 수 있습니다.

+ +
'use strict';
+var obj = Object.freeze({name: 'Elsa', score: 157});
+obj.score = 0;  // TypeError
+
+'use strict';
+Object.defineProperty(this, 'LUNG_COUNT', {value: 2, writable: false});
+LUNG_COUNT = 3;  // TypeError
+
+'use strict';
+var frozenArray = Object.freeze([0, 1, 2]);
+frozenArray[0]++;  // TypeError
+
+ +

자바 스크립트에는 몇 가지 읽기 전용 속성이 내장되어 있습니다. 아마도 수학적 상수를 재정의하려고 한 것 같습니다.

+ +
'use strict';
+Math.PI = 4;  // TypeError
+
+ +

이렇게는 불가능합니다.

+ +

전역변수 undefined  또한 읽기전용으로, 사람들이 모두 좋아하지 않는 "undefined is not a function" 에러가 다음과 같은 경우 등장합니다:

+ +
'use strict';
+undefined = function() {};  // TypeError: "undefined" is read-only
+
+ +

적절한 예

+ +
'use strict';
+var obj = Object.freeze({name: 'Score', points: 157});
+obj = {name: obj.name, points: 0};   // replacing it with a new object works
+
+'use strict';
+var LUNG_COUNT = 2;  // a `var` works, because it's not read-only
+LUNG_COUNT = 3;  // ok (anatomically unlikely, though)
+
+ +

더보기

+ + diff --git a/files/ko/web/javascript/reference/errors/reduce_of_empty_array_with_no_initial_value/index.html b/files/ko/web/javascript/reference/errors/reduce_of_empty_array_with_no_initial_value/index.html new file mode 100644 index 0000000000..53796ea87f --- /dev/null +++ b/files/ko/web/javascript/reference/errors/reduce_of_empty_array_with_no_initial_value/index.html @@ -0,0 +1,83 @@ +--- +title: 'TypeError: Reduce of empty array with no initial value' +slug: Web/JavaScript/Reference/Errors/Reduce_of_empty_array_with_no_initial_value +translation_of: Web/JavaScript/Reference/Errors/Reduce_of_empty_array_with_no_initial_value +--- +
{{jsSidebar("Errors")}}
+ +

Message

+ +
TypeError: 초기값이 없는 빈 배열에 대한 recude는 에러
+
+ +

Error type

+ +

{{jsxref("TypeError")}}

+ +

What went wrong?

+ +

자바스크립크에서 몇 몇의 reduce 함수들:

+ + + +

이러한 함수들은 선택적으로 초기값(initialValue)을 사용합니다.(콜백(callback)의 첫번째 호출에 대한 첫번째 인수로 사용됩니다.) 그러나, 만약에 초기값을 설정하지 않는다면, {{jsxref("Array")}} or {{jsxref("TypedArray")}}에 대한 첫번째 엘리먼트를 초기값으로 사용 합니다. 이런 경우에 초기값이 없기 때문에 빈 배열이 제공될 경우 오류가 발생 합니다.

+ +

Examples

+ +

Invalid cases

+ +

This problem appears frequently when combined with a filter ({{jsxref("Array.prototype.filter()")}}, {{jsxref("TypedArray.prototype.filter()")}}) which will remove all elements of the list. Thus leaving none to be used as the initial value.

+ +
var ints = [0, -1, -2, -3, -4, -5];
+ints.filter(x => x > 0)         // removes all elements
+    .reduce((x, y) => x + y)    // no more elements to use for the initial value.
+ +

Similarly, the same issue can happen if there is a typo in a selector, or an unexpected number of elements in a list:

+ +
var names = document.getElementsByClassName("names");
+var name_list = Array.prototype.reduce.call(names, (acc, name) => acc + ", " + name);
+
+ +

Valid cases

+ +

These problems can be solved in two different ways.

+ +

One way is to actually provide an initialValue  as the neutral element of the operator, such as 0 for the addition, 1 for a multiplication, or an empty string for a concatenation.

+ +
var ints = [0, -1, -2, -3, -4, -5];
+ints.filter(x => x > 0)         // removes all elements
+    .reduce((x, y) => x + y, 0) // the initial value is the neutral element of the addition
+
+ +

Another way would be two to handle the empty case, either before calling reduce, or in the callback after adding an unexpected dummy initial value.

+ +
var names = document.getElementsByClassName("names");
+
+var name_list1 = "";
+if (names1.length >= 1)
+  name_list1 = Array.prototype.reduce.call(names, (acc, name) => acc + ", " + name);
+// name_list1 == "" when names is empty.
+
+var name_list2 = Array.prototype.reduce.call(names, (acc, name) => {
+  if (acc == "") // initial value
+    return name;
+  return acc + ", " + name;
+}, "");
+// name_list2 == "" when names is empty.
+
+ +

See also

+ + diff --git a/files/ko/web/javascript/reference/errors/reserved_identifier/index.html b/files/ko/web/javascript/reference/errors/reserved_identifier/index.html new file mode 100644 index 0000000000..8a1932d9cc --- /dev/null +++ b/files/ko/web/javascript/reference/errors/reserved_identifier/index.html @@ -0,0 +1,80 @@ +--- +title: 'SyntaxError: "x" is a reserved identifier' +slug: Web/JavaScript/Reference/Errors/Reserved_identifier +tags: + - 구문 에러 + - 예약어 + - 자바스크립트 +translation_of: Web/JavaScript/Reference/Errors/Reserved_identifier +--- +
{{jsSidebar("Errors")}}
+ +

메세지

+ +
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)
+ +

에러 타입

+ +

{{jsxref("SyntaxError")}}

+ +

무엇이 잘못되었을까?

+ +

예약어가 식별자로 쓰인 경우 발생하는 에러입니다. 이 키워드는 엄격(Strict) 모드와 느슨한(Sloppy) 모드에서 모두 예약어로 취급됩니다.

+ + + +

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

+ + + +

예제

+ +

엄격 모드와 엄격하지 않은 모드에서의 예약어

+ +

enum 식별자는 일반적으로 예약되어 있습니다.

+ +
var enum = { RED: 0, GREEN: 1, BLUE: 2 };
+// SyntaxError: enum is a reserved identifier
+
+ +

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

+ +
"use strict";
+var package = ["potatoes", "rice", "fries"];
+// SyntaxError: package is a reserved identifier
+
+ +

이 변수들의 이름을 변경해야 합니다.

+ +
var colorEnum = { RED: 0, GREEN: 1, BLUE: 2 };
+var list = ["potatoes", "rice", "fries"];
+ +

오래된 브라우저의 업데이트

+ +

새로운 구문을 사용하기 위해서는 최근 버전의 브라우저로 업데이트 해야 합니다. 예를 들어, 오래된 브라우저를 사용하고 있다면 let 또는 class 구현할 수 없습니다.

+ +
"use strict";
+class DocArchiver {}
+
+// SyntaxError: class is a reserved identifier
+// (오래된 버전의 브라우저에서만 에러가 발생합니다. 예) Firefox 44 이하)
+
+ +

같이 보기

+ + diff --git a/files/ko/web/javascript/reference/errors/resulting_string_too_large/index.html b/files/ko/web/javascript/reference/errors/resulting_string_too_large/index.html new file mode 100644 index 0000000000..20e28cbe2b --- /dev/null +++ b/files/ko/web/javascript/reference/errors/resulting_string_too_large/index.html @@ -0,0 +1,46 @@ +--- +title: 'RangeError: repeat count must be less than infinity' +slug: Web/JavaScript/Reference/Errors/Resulting_string_too_large +translation_of: Web/JavaScript/Reference/Errors/Resulting_string_too_large +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
RangeError: repeat count must be less than infinity and not overflow maximum string size (Firefox)
+(repeat count는 infinity보다 작아야하며, 최대 문자열 크기를 넘길 수 없습니다.)
+
+RangeError: Invalid count value (Chrome)
+
+ +

에러 형식

+ +

{{jsxref("RangeError")}}

+ +

무엇이 잘못되었을까?

+ +

 {{jsxref("String.prototype.repeat()")}} 메소드가 사용되었습니다. 이 메소드는 문자열을 반복하는 수를 예측하는 카운트 파라메터를 가지고 있었습니다. 그리고 이 파라메터는 0보다 커야하며, 양의 {{jsxref("Infinity")}} 보다 작아야 했으며, 음수는 허용되지 않았습니다. 이 값의 허용 범위는 이렇게 표현될 수 있습니다. : [0, +∞). 

+ +

결과인 문자열은 최대 문자열 크기보다 클 수 없지만, JavaScript 에서는 다를 수 있습니다. Firefox (SpiderMonkey) 에서의 최대 문자열 크기는 228 -1 (0xFFFFFFF)입니다.

+ +

+ +

허용되지 않는 경우

+ +
'abc'.repeat(Infinity); // RangeError
+'a'.repeat(2**28);      // RangeError
+
+ +

허용되는 경우

+ +
'abc'.repeat(0);    // ''
+'abc'.repeat(1);    // 'abc'
+'abc'.repeat(2);    // 'abcabc'
+'abc'.repeat(3.5);  // 'abcabcabc' (숫자는 정수로 변환될 것입니다.)
+
+ +

참조

+ + diff --git a/files/ko/web/javascript/reference/errors/strict_non_simple_params/index.html b/files/ko/web/javascript/reference/errors/strict_non_simple_params/index.html new file mode 100644 index 0000000000..8c07f4b46a --- /dev/null +++ b/files/ko/web/javascript/reference/errors/strict_non_simple_params/index.html @@ -0,0 +1,107 @@ +--- +title: 'SyntaxError: "use strict" not allowed in function with non-simple parameters' +slug: Web/JavaScript/Reference/Errors/Strict_Non_Simple_Params +translation_of: Web/JavaScript/Reference/Errors/Strict_Non_Simple_Params +--- +
{{jsSidebar("Errors")}}
+ +

Message

+ +
Firefox:
+SyntaxError: "use strict" not allowed in function with default parameter
+SyntaxError: "use strict" not allowed in function with rest parameter
+SyntaxError: "use strict" not allowed in function with destructuring parameter
+
+Chrome:
+SyntaxError: Illegal 'use strict' directive in function with non-simple parameter list
+
+ +

Error type

+ +

{{jsxref("SyntaxError")}}.

+ +

무엇이 잘못 되었을까요?

+ +

 "use strict" 지시문은 다음 매개변수 중 한 개가 있는 함수의 맨 위에 작성됩니다:

+ + + +

"use strict" 지시문은 ECMAScript 동작에 따라 이러한 함수의 맨 위에 허용되지 않습니다.

+ +

Examples

+ +

기능 명세서

+ +

다음은 함수 sum 에는 기본 매개 변수 a=1b=2가 있는 경우입니다:

+ +
function sum(a = 1, b = 2) {
+  // SyntaxError: "use strict" not allowed in function with default parameter
+  'use strict';
+  return a + b;
+}
+
+ +

함수가 strict mode 모드에 있어야 하고 전체 스크립트 또는 포함된 함수가 strict mode에 있어도 괜찮으면 함수 외부에서 "use strict" 지시문을 이동할 수 있습니다:

+ +
'use strict';
+function sum(a = 1, b = 2) {
+  return a + b;
+}
+
+ +

함수 표현식

+ +

함수 표현식은 또 다른 해결방법을 사용할 수 있습니다:

+ +
var sum = function sum([a, b]) {
+  // SyntaxError: "use strict" not allowed in function with destructuring parameter
+  'use strict';
+  return a + b;
+};
+
+ +

이것은 다음 표현식으로 변환 될 수 있습니다:

+ +
var sum = (function() {
+  'use strict';
+  return function sum([a, b]) {
+    return a + b;
+  };
+})();
+
+ +

화살표 함수

+ +

화살표 함수가 this에 접근해야 하는 경우에는,  둘러싼 함수로 화살표 함수를 사용할 수 있습니다:

+ +
var callback = (...args) => {
+  // SyntaxError: "use strict" not allowed in function with rest parameter
+  'use strict';
+  return this.run(args);
+};
+
+ +

이것은 다음 표현식과 같이 변환될 수 있습니다:

+ +
var callback = (() => {
+  'use strict';
+  return (...args) => {
+    return this.run(args);
+  };
+})();
+
+ +

See also

+ + diff --git a/files/ko/web/javascript/reference/errors/too_much_recursion/index.html b/files/ko/web/javascript/reference/errors/too_much_recursion/index.html new file mode 100644 index 0000000000..90495a359b --- /dev/null +++ b/files/ko/web/javascript/reference/errors/too_much_recursion/index.html @@ -0,0 +1,50 @@ +--- +title: 'InternalError: too much recursion' +slug: Web/JavaScript/Reference/Errors/Too_much_recursion +translation_of: Web/JavaScript/Reference/Errors/Too_much_recursion +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
InternalError: too much recursion
+
+ +

에러 형식

+ +

InternalError.

+ +

무엇이 잘못되었을까?

+ +

자신을 호출하는 함수를 재귀 함수라고 합니다. 어떤 면에서, 재귀는 반복과 유사합니다. 둘 다 같은 코드를 여러 번 실행하며, 조건(무한 반복 피하기, 더 정확히 여기서 말하는 무한 재귀)이 있습니다. 너무 많거나 무한 번의 재귀가 발생할 경우, JavaScript는 이 에러를 던질 것입니다.

+ +

+ +

이 재귀 함수는 exit 조건에 따라 10번을 실행합니다.

+ +
function loop(x) {
+  if (x >= 10) // "x >= 10" is the exit condition
+    return;
+  // do stuff
+  loop(x + 1); // the recursive call
+}
+loop(0);
+ +

이 조건에 대하여 너무 높은 값을 설정 하면 작동하지 않게 됩니다.

+ +
function loop(x) {
+  if (x >= 1000000000000)
+    return;
+  // do stuff
+  loop(x + 1);
+}
+loop(0);
+
+// InternalError: too much recursion
+ +

참조

+ + diff --git a/files/ko/web/javascript/reference/errors/undeclared_var/index.html b/files/ko/web/javascript/reference/errors/undeclared_var/index.html new file mode 100644 index 0000000000..688c92473d --- /dev/null +++ b/files/ko/web/javascript/reference/errors/undeclared_var/index.html @@ -0,0 +1,62 @@ +--- +title: 'ReferenceError: assignment to undeclared variable "x"' +slug: Web/JavaScript/Reference/Errors/Undeclared_var +translation_of: Web/JavaScript/Reference/Errors/Undeclared_var +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
ReferenceError: assignment to undeclared variable "x" (Firefox)
+ReferenceError: "x" is not defined (Chrome)
+ReferenceError: Variable undefined in strict mode (Edge)
+
+ +

에러 형식

+ +

엄격 모드(strict mode)에서만 발생하는 {{jsxref("ReferenceError")}} 경고.

+ +

무엇이 잘못되었을까?

+ +

선언되지 않은 변수로 값은 할당되었습니다. var 키워드가 없이 할당이 된 것입니다. 선언된 변수와 선언되지 않은 변수 사이에는 차이가 있는데, 이는 예상치 못한 결과를 가져오며, 때문에 JavaScript 엄격모드에서는 에러를 발생시키고 있습니다.

+ +

선언된 변수와 선언되지 않은 변수에 대하여 기억해야 할 세 가지:

+ + + +

더 많은 설명과 예제를 필요로 한다면 이 var 참조문서 페이지를 보세요.

+ +

선언되지 않은 변수 할당에 대한 에러는 엄격 모드(strict mode code)에서만 발생합니다. 비-엄격 코드에서는 조용히 묵인됩니다.

+ +

+ +

허용되지 않는 경우

+ +

이런 경우에는, 변수 "bar"는 선언되지 않은 변수가 됩니다.

+ +
function foo() {
+  "use strict";
+  bar = true;
+}
+foo(); // ReferenceError: assignment to undeclared variable bar
+
+ +

허용되는 경우

+ +

"bar" 를 선언된 변수로 만들기 위해서, var 키워드를 변수명 앞에 붙여줍니다.

+ +
function foo() {
+  "use strict";
+  var bar = true;
+}
+foo();
+ +

참조

+ + diff --git a/files/ko/web/javascript/reference/errors/undefined_prop/index.html b/files/ko/web/javascript/reference/errors/undefined_prop/index.html new file mode 100644 index 0000000000..7919ca877d --- /dev/null +++ b/files/ko/web/javascript/reference/errors/undefined_prop/index.html @@ -0,0 +1,58 @@ +--- +title: 'ReferenceError: reference to undefined property "x"' +slug: Web/JavaScript/Reference/Errors/Undefined_prop +translation_of: Web/JavaScript/Reference/Errors/Undefined_prop +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
ReferenceError: reference to undefined property "x" (Firefox)
+
+ +

에러 형식

+ +

엄격 모드(strict mode)에서만 발생하는 {{jsxref("ReferenceError")}} 경고.

+ +

무엇이 잘못되었을까?

+ +

이 스크립트는 존재하지 않는 객체의 속성에 접근을 시도했습니다. 요소에 접근하는 방법에는 두 가지가 있습니다.; 더 자세히 알고 싶으시다면, 속성 접근자(property accessors) 참조 문서를 봐주세요. 

+ +

정의되지 않은 속성 참조에 대한 에러는 엄격 모드 코드(strict mode code)에서만 발생합니다. 비-엄격모드의 코드에서는 존재하지 않는 속성에 대한 접근은 조용히 무시됩니다.

+ +

+ +

허용되지 않는 경우

+ +

이 경우에는, 속성 bar 는 정의되지 않은 속성으로, ReferenceError 가 발생합니다.

+ +
"use strict";
+
+var foo = {};
+foo.bar; // ReferenceError: reference to undefined property "bar"
+
+ +

허용되는 경우

+ +

에러를 피하기 위해서는, 접근을 시도하기 앞서, 객체에 bar 에 대한 정의를 추가하거나 bar 속성의 존재 여부를 확인해야 합니다.; 아래와 같이 {{jsxref("Object.prototype.hasOwnProperty()")}} method)를 사용하는 것이 하나의 방법이 될 수 있습니다.:

+ +
"use strict";
+
+var foo = {};
+
+// bar 속성을 정의한다.
+
+foo.bar = "moon";
+console.log(foo.bar); // "moon"
+
+// bar에 접근하기 전에 존재 하는지 확인한다.
+
+if (foo.hasOwnProperty("bar") {
+  console.log(foo.bar);
+}
+ +

참조

+ + diff --git a/files/ko/web/javascript/reference/errors/unexpected_token/index.html b/files/ko/web/javascript/reference/errors/unexpected_token/index.html new file mode 100644 index 0000000000..91704a6006 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/unexpected_token/index.html @@ -0,0 +1,49 @@ +--- +title: 'SyntaxError: Unexpected token' +slug: Web/JavaScript/Reference/Errors/Unexpected_token +tags: + - 에러 + - 자바스크립트 +translation_of: Web/JavaScript/Reference/Errors/Unexpected_token +--- +
{{jsSidebar("Errors")}}
+ +

메시지

+ +
SyntaxError: expected expression, got "x"
+SyntaxError: expected property name, got "x"
+SyntaxError: expected target, got "x"
+SyntaxError: expected rest argument name, got "x"
+SyntaxError: expected closing parenthesis, got "x"
+SyntaxError: expected '=>' after argument list, got "x"
+
+ +

에러 타입

+ +

{{jsxref("SyntaxError")}}

+ +

무엇이 잘못되었나요?

+ +

특정 언어 구조를 예상했지만 무언가 다른 것이 있었습니다. 아마도, 간단한 오타일 것입니다.

+ +

예제

+ +

예상하지 못한 표현식

+ +

예를 들어, 함수를 호출할 때, 인수에서 마지막 부분에 콤마는 허용되지 않습니다. 자바스크립트는 계속해서 다른 인자가 있을 것이라고 기대하기 때문입니다.

+ +
Math.max(2, 42,);
+// SyntaxError: expected expression, got ')'
+
+ +

콤마를 생략하거나 다른 인수를 추가해 수정할 수 있습니다.

+ +
Math.max(2, 42);
+Math.max(2, 42, 13+37);
+
+ +

참조

+ + diff --git a/files/ko/web/javascript/reference/errors/unexpected_type/index.html b/files/ko/web/javascript/reference/errors/unexpected_type/index.html new file mode 100644 index 0000000000..527411ab9a --- /dev/null +++ b/files/ko/web/javascript/reference/errors/unexpected_type/index.html @@ -0,0 +1,67 @@ +--- +title: 'TypeError: "x" is (not) "y"' +slug: Web/JavaScript/Reference/Errors/Unexpected_type +tags: + - Errors + - JavaScript + - TypeError +translation_of: Web/JavaScript/Reference/Errors/Unexpected_type +--- +
{{jsSidebar("Errors")}}
+ +

Message

+ +
TypeError: "x" is (not) "y"
+
+Examples:
+TypeError: "x" is undefined
+TypeError: "x" is null
+TypeError: "undefined" is not an object
+TypeError: "x" is not an object or null
+TypeError: "x" is not a symbol
+
+ +

Error type

+ +

{{jsxref("TypeError")}}.

+ +

What went wrong?

+ +

그것은 정확하지 않은 형태이다. 그것은 가끔{{jsxref("undefined")}} 나 {{jsxref("null")}} 값을 발생한다.

+ +

또한, {{jsxref("Object.create()")}} 또는 {{jsxref("Symbol.keyFor()")}}와 같은 메서드는 반드시 제공되어야하는 특별한 형태를 요구한다.

+ +

Examples

+ +

Invalid cases

+ +
// undefined and null cases on which the substring method won't work
+var foo = undefined;
+foo.substring(1); // TypeError: foo is undefined
+
+var foo = null;
+foo.substring(1); // TypeError: foo is null
+
+
+// Certain methods might require a specific type
+var foo = {}
+Symbol.keyFor(foo); // TypeError: foo is not a symbol
+
+var foo = 'bar'
+Object.create(foo); // TypeError: "foo" is not an object or null
+
+ +

Fixing the issue

+ +

undefined 나 null 값을 가진 null 포인터를 고치기 위해서 아래 예제와 같이 typeof 연산자를 사용할 수 있다.

+ +
if (typeof foo !== 'undefined') {
+  // Now we know that foo is defined, we are good to go.
+}
+ +

See also

+ + diff --git a/files/ko/web/javascript/reference/errors/unnamed_function_statement/index.html b/files/ko/web/javascript/reference/errors/unnamed_function_statement/index.html new file mode 100644 index 0000000000..b7afe67563 --- /dev/null +++ b/files/ko/web/javascript/reference/errors/unnamed_function_statement/index.html @@ -0,0 +1,118 @@ +--- +title: 'SyntaxError: function statement requires a name' +slug: Web/JavaScript/Reference/Errors/Unnamed_function_statement +tags: + - IIEF + - 객체 메소드 + - 구문 에러 + - 자바스크립트 + - 콜백 함수 + - 함수 이름 +translation_of: Web/JavaScript/Reference/Errors/Unnamed_function_statement +--- +
{{jsSidebar("Errors")}}
+ +

메세지

+ +
Syntax Error: Expected identifier (Edge)
+SyntaxError: function statement requires a name [Firefox]
+SyntaxError: Unexpected token ( [Chrome]
+
+ +

에러 타입

+ +

{{jsxref("SyntaxError")}}

+ +

무엇이 잘못되었을까?

+ +

함수 구문(Function statement)은 이름이 필수입니다. 함수가 정의된 방법에 따라 함수의 이름을 짓거나 함수 표현식(Function expression) {{Glossary("IIFE")}}으로 작성하거나, 함수가 맥락에 맞게 제대로 작성되었는지 확인해야 합니다.

+ +

예제

+ +

구문 vs 표현식

+ +

함수 구문(또는 함수 선언)은 이름이 필요하므로 아래 예제는 동작하지 않습니다:

+ +
function () {
+  return 'Hello world';
+}
+// SyntaxError: function statement requires a name
+
+ +

대신 함수 표현식을 사용할 수 있습니다:

+ +
var greet = function() {
+  return 'Hello world';
+};
+ +

또는, 선언하자마자 바로 실행되는 IIFE (Immediately Invoked Function Expression)를 사용할 수 있습니다. 이 경우 몇 개의 괄호가 더 필요합니다:

+ +
(function () {
+
+})();
+ +

레이블을 붙인 함수

+ +

만약 함수 레이블을 사용하는 경우 function 키워드 뒤에 함수 이름이 필요하므로 아래 예제는 동작하지 않습니다:

+ +
function Greeter() {
+  german: function () {
+    return "Moin";
+  }
+}
+// SyntaxError: function statement requires a name
+
+ +

아래 예제는 동작합니다:

+ +
function Greeter() {
+  german: function g() {
+    return "Moin";
+  }
+}
+ +

객체 메소드

+ +

만약 객체 메소드를 만드는 경우 먼저 객체를 만들어야 합니다. 객체 메소드의 경우 아래 예제와 같이 function 키워드 뒤에 이름이 없어도 정상적으로 동작합니다.

+ +
var greeter = {
+  german: function () {
+    return "Moin";
+  }
+};
+ +

콜백 구문

+ +

콜백을 사용하는 경우 구문을 확인해야 합니다. 괄호와 쉼표는 구문을 어렵게 만듭니다.

+ +
promise.then(
+  function() {
+    console.log("success");
+  });
+  function() {
+    console.log("error");
+}
+// SyntaxError: function statement requires a name
+
+ +

올바르게 변경하면:

+ +
promise.then(
+  function() {
+    console.log("success");
+  },
+  function() {
+    console.log("error");
+  }
+);
+
+ +

같이 보기

+ + -- cgit v1.2.3-54-g00ecf