From da78a9e329e272dedb2400b79a3bdeebff387d47 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:17 -0500 Subject: initial commit --- .../it/web/javascript/reference/errors/index.html | 31 +++++++++ .../errors/invalid_array_length/index.html | 77 +++++++++++++++++++++ .../invalid_assignment_left-hand_side/index.html | 54 +++++++++++++++ .../missing_semicolon_before_statement/index.html | 78 ++++++++++++++++++++++ .../reference/errors/too_much_recursion/index.html | 72 ++++++++++++++++++++ .../reference/errors/unexpected_token/index.html | 50 ++++++++++++++ .../reference/errors/unexpected_type/index.html | 67 +++++++++++++++++++ 7 files changed, 429 insertions(+) create mode 100644 files/it/web/javascript/reference/errors/index.html create mode 100644 files/it/web/javascript/reference/errors/invalid_array_length/index.html create mode 100644 files/it/web/javascript/reference/errors/invalid_assignment_left-hand_side/index.html create mode 100644 files/it/web/javascript/reference/errors/missing_semicolon_before_statement/index.html create mode 100644 files/it/web/javascript/reference/errors/too_much_recursion/index.html create mode 100644 files/it/web/javascript/reference/errors/unexpected_token/index.html create mode 100644 files/it/web/javascript/reference/errors/unexpected_type/index.html (limited to 'files/it/web/javascript/reference/errors') diff --git a/files/it/web/javascript/reference/errors/index.html b/files/it/web/javascript/reference/errors/index.html new file mode 100644 index 0000000000..c295fccea6 --- /dev/null +++ b/files/it/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/it/web/javascript/reference/errors/invalid_array_length/index.html b/files/it/web/javascript/reference/errors/invalid_array_length/index.html new file mode 100644 index 0000000000..61ee1cba5f --- /dev/null +++ b/files/it/web/javascript/reference/errors/invalid_array_length/index.html @@ -0,0 +1,77 @@ +--- +title: 'RangeError: invalid array length' +slug: Web/JavaScript/Reference/Errors/Invalid_array_length +tags: + - Errori + - JavaScript + - RangeError +translation_of: Web/JavaScript/Reference/Errors/Invalid_array_length +--- +
{{jsSidebar("Errors")}}
+ +

Messaggio

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

Tipo di errore

+ +

{{jsxref("RangeError")}}

+ +

Cosa è andato storto?

+ +

Un invalid array length può comparire in queste situazioni:

+ + + +

Perché la lunghezza di Array e ArrayBuffer è limitata? La proprietà length di un Array o di un ArrayBuffer è rappresentata da un intero di 32-bit  senza segno, che quindi permette di memorizzare valori nell'intervallo da 0 a 232 - 1.

+ +

Se stai creando un Array utilizzando il costruttore, potresti invece utilizzare la notazione letterale dove il primo argomento è interpretato come la lunghezza dell' Array.

+ +

Altrimenti, potresti voler bloccare la lunghezza prima di settare la proprietà length, o utilizzarla come argomento del costruttore.

+ +

Esempi

+ +

Casi non validi

+ +
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;         // setta -1 alla proprietà length
+
+let b = new Array(Math.pow(2, 32) - 1);
+b.length = b.length + 1;         // setta 2^32 alla proprietà length
+
+ +

Casi validi

+ +
[ 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 è la notazione esadecimale di 2^32 - 1
+// che può essere riscritta come (-1 >>> 0)
+
+ +

Guarda anche

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

Messaggio

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

Tipo di errore

+ +

{{jsxref("ReferenceError")}}.

+ +

Che cosa è andato storto?

+ +

C'è stato un assegnamento inaspettato da qualche parte. Ciò, ad esempio, potrebbe essere dovuto alla confusione tra  l' operatore d'assegnazione e l' operatore di confronto. Mentre un solo segno  di "=" assegna un valore ad una variabile, l'operatore "==" o "===" effettua il confronto tra valori.

+ +

Esempi

+ +
if (Math.PI = 3 || Math.PI = 4) {
+  console.log('niente!');
+}
+// ReferenceError: invalid assignment left-hand side
+
+var str = 'Ciao, '
++= 'sono io '
++= 'cosa stai cercando?';
+// ReferenceError: invalid assignment left-hand side
+
+ +

Nella dichiarazione if, puoi usare un operatore di confronto ("=="), e per la concatenazione di stringhe è necessario  l'operatore più ("+").

+ +
if (Math.PI == 3 || Math.PI == 4) {
+  console.log('niente!');
+}
+
+var str = 'Ciao, '
++ 'dall/' '
++ 'altra parte!';
+
+ +

Guarda anche

+ + diff --git a/files/it/web/javascript/reference/errors/missing_semicolon_before_statement/index.html b/files/it/web/javascript/reference/errors/missing_semicolon_before_statement/index.html new file mode 100644 index 0000000000..c49646b4b1 --- /dev/null +++ b/files/it/web/javascript/reference/errors/missing_semicolon_before_statement/index.html @@ -0,0 +1,78 @@ +--- +title: 'SyntaxError: missing ; before statement' +slug: Web/JavaScript/Reference/Errors/Missing_semicolon_before_statement +tags: + - Errore di Sintassi + - Errori + - JavaScript + - Oggetti + - SyntaxError + - Variabili +translation_of: Web/JavaScript/Reference/Errors/Missing_semicolon_before_statement +--- +
{{jsSidebar("Errors")}}
+ +

Messaggio

+ +
SyntaxError: Expected - Previsto ';' (Edge)
+SyntaxError: missing  - Mancante; prima della dichiarazione (Firefox)
+
+ +

 

+ +

Tipo di errore

+ +

{{jsxref("SyntaxError")}}.

+ +

Cosa è andato storto?

+ +

C'è un punto e virgola (;) mancante. Le dichiarazioni in JavaScript devono essere determinate da il punto e virgola (;). Alcune di loro sono soggette all' Inserzione Automatica a Semicolonne (ASI), ma in questo caso è necessario specificare la semicolonna, in modo che JavaScript legga correttamente il codice sorgente.

+ +

In ogni caso, molto spesso, questo errore è solo una conseguenza di un altro, come lo scorretto uso degli apici, o l'uso errato di var. Potresti anche avere troppe parentesi da qualche parte. Ricontrolla la sintassi del codice quando appare questo errore.

+ +

Esempi

+ +

Stringhe senza escape (\)

+ +

Questo errore accade frequentemente quando si usa un apostrofo senza carattere di escape. Il motore di JavaScript si aspetta la fine di una stringa. Per esempio:

+ +
var foo = 'Tom's bar';
+// (') interrompe è atteso ("..'..") o ('..\'..')
+// SyntaxError: missing ; prima della dichiarazione
+ +

Per risolvere, usa le virgolette oppure un carattere di escape (backslash):

+ +
var foo = "Tom's bar"; <- in questo modo
+var foo = 'Tom\'s bar'; <- in questo modo
+
+ +

 

+ +

Dichiarare le proprietà con var

+ +

Non puoi dichiarare le proprietà di un oggetto o di un array con una dichiarazione var.

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

Prova invece ad omettere la parola chiave var:

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

Controlla anche

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

The JavaScript exception "too much recursion" or "Maximum call stack size exceeded" occurs when there are too many function calls, or a function is missing a base case.

+ +

Message

+ +
Error: Spazio nello stack esaurito (Edge)
+InternalError: Troppa ricorsione (Firefox)
+RangeError: Dimensioni massime dello stack superate (Chrome)
+
+ +

Error type

+ +

{{jsxref("InternalError")}}.

+ +

Cos'è andato storto?

+ +

Una funzione che si chiama da sola si chiama funzione ricorsiva. Una volta che la condizione è soddisfatta, la funzione smette di chiamarsi. Questo si chiama caso di base.

+ +

In certi versi, la ricorsione è analoga ai cicli. Entrambi eseguono lo stesso codice più volte, ed entrambi richiedono una condizione(per evitare cicli infiniti,o in questo caso, ricorsioni infinite). Quando ci sono troppe chiamate, o manca il caso di base , JavaScript lancerà questo errore.

+ +

Esempi

+ +

Questa funzione ricorsiva si chiama 10 volte, secondo le condizioni d'uscita

+ +
function ciclo(x) {
+  if (x >= 10) // "x >= 10" condizione d'uscita
+    return;
+  // do stuff
+  ciclo(x + 1); // chiamata ricorsiva
+}
+ciclo(0);
+ +

Impostare questa condizione a valori estremamente alti non funzionerà:

+ +
function ciclo(x) {
+  if (x >= 1000000000000)
+    return;
+  // fà cose
+  ciclo(x + 1);
+}
+ciclo(0);
+
+// Errore Interno: troppa ricorsione
+ +

Alla funzione manca un caso base.Visto che non c'è condizione di uscita, la funzione chiama se stessa all'infinito.

+ +
function ciclo(x) {
+ // Manca caso base
+
+ciclo(x + 1); // Chiamata ricorsiva
+}
+
+ciclo(0);
+
+// Errore Interno: troppa ricorsione
+ +

Vedi anche

+ + + + diff --git a/files/it/web/javascript/reference/errors/unexpected_token/index.html b/files/it/web/javascript/reference/errors/unexpected_token/index.html new file mode 100644 index 0000000000..17a9c78a4c --- /dev/null +++ b/files/it/web/javascript/reference/errors/unexpected_token/index.html @@ -0,0 +1,50 @@ +--- +title: 'SyntaxError: Unexpected token' +slug: Web/JavaScript/Reference/Errors/Unexpected_token +tags: + - Errori + - JavaScript + - Sintassi +translation_of: Web/JavaScript/Reference/Errors/Unexpected_token +--- +
{{jsSidebar("Errors")}}
+ +

Messaggio

+ +
SyntaxError: espressione prevista, si ottiene "x"
+SyntaxError: nome proprietà previsto, si ottiene "x"
+SyntaxError: target previsto, si ottiene "x"
+SyntaxError: nome dell'argomento rest previsto, si ottiene "x"
+SyntaxError: parentesi di chiusura prevista, si ottiene "x"
+SyntaxError: previsto '=>' dopo la lista degli argomenti, si ottiene "x"
+
+ +

Tipo di errore

+ +

{{jsxref("SyntaxError")}}

+ +

Cosa è andato storto?

+ +

Era atteso un costrutto specifico del linguaggio, ma è stato fornito qualcosa di diverso. Potrebbe trattarsi di un semplice errore di digitazione.

+ +

Esempi

+ +

Espressione prevista

+ +

Ad esempio, non è permesso terminare una lista di argomenti con la virgola, in quanto JavaScript si aspetta un altro argomento.

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

Sarebbe invece corretto omettere la virgola o specificare un altro argomento (che potrebbe anche essere un espressione):

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

Vedi anche

+ + diff --git a/files/it/web/javascript/reference/errors/unexpected_type/index.html b/files/it/web/javascript/reference/errors/unexpected_type/index.html new file mode 100644 index 0000000000..632b9bf756 --- /dev/null +++ b/files/it/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: + - Errori + - JavaScript + - TypeError +translation_of: Web/JavaScript/Reference/Errors/Unexpected_type +--- +
{{jsSidebar("Errors")}}
+ +

Messaggio

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

Tipo di errore

+ +

{{jsxref("TypeError")}}.

+ +

Cosa è andato storto?

+ +

C'è stato un tipo inaspettato. Questo accade spesso con valori {{jsxref("undefined")}} o {{jsxref("null")}}.

+ +

Inoltre, alcuni metodi, come {{jsxref("Object.create()")}} o {{jsxref("Symbol.keyFor()")}}, richiedono che sia fornito un tipo specifico.

+ +

Esempi

+ +

Casi non validi

+ +
// casi undefined e null in cui il metodo substring non funzionerà
+var foo = undefined;
+foo.substring(1); // TypeError: foo non è definita
+
+var foo = null;
+foo.substring(1); // TypeError: foo è null
+
+
+// Alcuni metodi potrebbero richiedere un tipo specifico
+var foo = {}
+Symbol.keyFor(foo); // TypeError: foo non è un simbolo
+
+var foo = 'bar'
+Object.create(foo); // TypeError: "foo" non è un oggetto o è null
+
+ +

Risolvere il problema

+ +

Per risolvere il problema di valori undefined o null, si può usare l'operatore typeof operator, ad esempio.

+ +
if (typeof foo !== 'undefined') {
+  // Ora sappiamo che foo è definita, possiamo procedere.
+}
+ +

Vedi anche

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