From 4b1a9203c547c019fc5398082ae19a3f3d4c3efe Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:41:15 -0500 Subject: initial commit --- .../bg/web/javascript/reference/errors/index.html | 31 ++++++++++ .../reference/errors/unexpected_type/index.html | 70 ++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 files/bg/web/javascript/reference/errors/index.html create mode 100644 files/bg/web/javascript/reference/errors/unexpected_type/index.html (limited to 'files/bg/web/javascript/reference/errors') diff --git a/files/bg/web/javascript/reference/errors/index.html b/files/bg/web/javascript/reference/errors/index.html new file mode 100644 index 0000000000..c295fccea6 --- /dev/null +++ b/files/bg/web/javascript/reference/errors/index.html @@ -0,0 +1,31 @@ +--- +title: JavaScript error reference +slug: Web/JavaScript/Reference/Errors +tags: + - Debugging + - Error + - Errors + - Exception + - JavaScript + - NeedsTranslation + - TopicStub + - exceptions +translation_of: Web/JavaScript/Reference/Errors +--- +

{{jsSidebar("Errors")}}

+ +

Below, you'll find a list of errors which are thrown by JavaScript. These errors can be a helpful debugging aid, but the reported problem isn't always immediately clear. The pages below will provide additional details about these errors. Each error is an object based upon the {{jsxref("Error")}} object, and has a name and a message.

+ +

Errors displayed in the Web console may include a link to the corresponding page below to help you quickly comprehend the problem in your code.

+ +

List of errors

+ +

In this list, each page is listed by name (the type of error) and message (a more detailed human-readable error message). Together, these two properties provide a starting point toward understanding and resolving the error. For more information, follow the links below!

+ +

{{ListSubPages("/en-US/docs/Web/JavaScript/Reference/Errors")}}

+ +

See also

+ + diff --git a/files/bg/web/javascript/reference/errors/unexpected_type/index.html b/files/bg/web/javascript/reference/errors/unexpected_type/index.html new file mode 100644 index 0000000000..372560f00e --- /dev/null +++ b/files/bg/web/javascript/reference/errors/unexpected_type/index.html @@ -0,0 +1,70 @@ +--- +title: 'TypeError: "x" is (not) "y"' +slug: Web/JavaScript/Reference/Errors/Unexpected_type +tags: + - JavaScript + - TypeError + - Грешки +translation_of: Web/JavaScript/Reference/Errors/Unexpected_type +--- +
{{jsSidebar("Errors")}}
+ +

Съобщение

+ +
TypeError: "x" is (not) "y"
+
+Примери:
+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
+
+ +

Вид на грешката

+ +

{{jsxref("TypeError")}}.

+ +

Какво се обърка?

+ +

Върнатият тип не отговаря на очакванията. Това се случва често при върната стойност {{jsxref("undefined")}} или {{jsxref("null")}}.

+ +

Някои методи като {{jsxref("Object.create()")}} или {{jsxref("Symbol.keyFor()")}} освен това изискват да им бъде предоставен определен тип.

+ +

Примери

+ +

Случаи, предизвикващи грешката

+ +
// Случаи, при които методът substring няма да работи.
+// Такива са undefined и null.
+var foo = undefined;
+foo.substring(1); // TypeError: foo is undefined
+
+var foo = null;
+foo.substring(1); // TypeError: foo is null
+
+
+// Методи, които очакват да бъдат извикани
+// върху точно определен тип.
+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
+
+ +

Поправяне на грешката

+ +

За да оправите грешката в случай на указател, сочещ към стойност undefined или null, можете да използвате оператора typeof.

+ +
if (typeof foo !== 'undefined') {
+  // Сега знаем, че foo има определена стойност
+  // и можем да продължим.
+}
+ +

Вижте също

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