aboutsummaryrefslogtreecommitdiff
path: root/files/ca/web/javascript/reference/errors
diff options
context:
space:
mode:
Diffstat (limited to 'files/ca/web/javascript/reference/errors')
-rw-r--r--files/ca/web/javascript/reference/errors/index.html31
-rw-r--r--files/ca/web/javascript/reference/errors/nomes-lectura/index.html78
2 files changed, 109 insertions, 0 deletions
diff --git a/files/ca/web/javascript/reference/errors/index.html b/files/ca/web/javascript/reference/errors/index.html
new file mode 100644
index 0000000000..c295fccea6
--- /dev/null
+++ b/files/ca/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
+---
+<p>{{jsSidebar("Errors")}}</p>
+
+<p>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 <code>name</code> and a <code>message</code>.</p>
+
+<p>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.</p>
+
+<h2 id="List_of_errors">List of errors</h2>
+
+<p>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!</p>
+
+<p>{{ListSubPages("/en-US/docs/Web/JavaScript/Reference/Errors")}}</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Learn/JavaScript/First_steps/What_went_wrong">What went wrong? Troubleshooting JavaScript</a>: Beginner's introductory tutorial on fixing JavaScript errors.</li>
+</ul>
diff --git a/files/ca/web/javascript/reference/errors/nomes-lectura/index.html b/files/ca/web/javascript/reference/errors/nomes-lectura/index.html
new file mode 100644
index 0000000000..30c70c40dd
--- /dev/null
+++ b/files/ca/web/javascript/reference/errors/nomes-lectura/index.html
@@ -0,0 +1,78 @@
+---
+title: 'TipusError: "x" es només de lectura'
+slug: Web/JavaScript/Reference/Errors/Nomes-Lectura
+tags:
+ - Errors
+ - JavaScript
+ - TypeError
+translation_of: Web/JavaScript/Reference/Errors/Read-only
+---
+<div>{{jsSidebar("Errors")}}</div>
+
+<h2 id="Missatge">Missatge</h2>
+
+<pre class="syntaxbox">TipusError: "x" es només de lectura (Firefox)
+TipusError: 0 es només de lectura (Firefox)
+TipusError: No es pot fer l'assignació a la propietat 'x' de #&lt;Object&gt; que es només de lectura (Chrome)
+TipusError: No es pot fer l'assignació a la propietat '0' de [object Array] (Chrome)
+</pre>
+
+<h2 id="Tipus_d'error">Tipus d'error</h2>
+
+<p>{{jsxref("TypeError")}}</p>
+
+<h2 id="Qué_ha_anat_malament">Qué ha anat malament?</h2>
+
+<p>La variable global o propietat de l'objecte a la qual s'ha volgut fer l'assignació es només de lectura. (Tècnicament, es una <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty#Writable_attribute">propietat de no-escriptura</a>.)</p>
+
+<p>Aquest error succeeix només en <a href="/en-US/docs/Web/JavaScript/Reference/Strict_mode">codi en mode estricte</a>. En codi en mode no estricte, l'assignació es ignorada de manera silenciosa.</p>
+
+<h2 id="Exemples">Exemples</h2>
+
+<h3 id="Casos_invàlids">Casos invàlids</h3>
+
+<p>Propietats de només lectura no son súper comuns, però es poden donar quan es fa servir {{jsxref("Object.defineProperty()")}} o {{jsxref("Object.freeze()")}}.</p>
+
+<pre class="brush: js example-bad">'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
+</pre>
+
+<p>També hi ha unes poques propietats de només lectura en la construcció de JavaScript. Potser que hagis provat de redefinir una constant matemàtica.</p>
+
+<pre class="brush: js example-bad">'use strict';
+Math.PI = 4; // TypeError</pre>
+
+<p>Ho sentim, no pots fer això.</p>
+
+<p>La variable global <code>undefined</code> també es només de lectura, llavors no pots silenciar l'infame error "undefined no es una funció" fent això:</p>
+
+<pre class="brush: js example-bad">'use strict';
+undefined = function() {}; // TypeError: "undefined" es només de lectura
+</pre>
+
+<h3 id="Valid_cases">Valid cases</h3>
+
+<pre class="brush: js example-good">'use strict';
+var obj = Object.freeze({name: 'Score', points: 157});
+obj = {name: obj.name, points: 0}; // reemplaçant-ho amb un nou objecte funciona
+
+'use strict';
+var LUNG_COUNT = 2; // Una `var` funciona, perque no es de només lectura
+LUNG_COUNT = 3; // ok (anatòmicament potser, però poc probable)
+</pre>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>{{jsxref("Object.defineProperty()")}}</li>
+ <li>{{jsxref("Object.freeze()")}}</li>
+</ul>