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/statements/empty/index.html | 102 +++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 files/it/web/javascript/reference/statements/empty/index.html (limited to 'files/it/web/javascript/reference/statements/empty') diff --git a/files/it/web/javascript/reference/statements/empty/index.html b/files/it/web/javascript/reference/statements/empty/index.html new file mode 100644 index 0000000000..bb10fd7165 --- /dev/null +++ b/files/it/web/javascript/reference/statements/empty/index.html @@ -0,0 +1,102 @@ +--- +title: empty +slug: Web/JavaScript/Reference/Statements/Empty +translation_of: Web/JavaScript/Reference/Statements/Empty +--- +
{{jsSidebar("Statements")}}
+ +

Un empty statement (istruzione vuota) è utilizzato per evitare di inserire uno statement nel caso in cui la sintassi JavaScript ne richieda uno.

+ +
{{EmbedInteractiveExample("pages/js/statement-empty.html")}}
+ + + +

Sintassi

+ +
;
+
+ +

Descrizione

+ +

L'empty statement è un punto e virgola (;) che indica che nessuno statement sarà eseguito, nonostante la sintassi JavaScript ne richieda uno. Il comportamento opposto, quando vuoi eseguire più statement ma JavaScript ne consente uno solo, è reso possibile dall'utilizzo di un block statement; esso ne combina diversi in un singolo statement .

+ +

Esempi

+ +

L'empty statement è utilizzato talvolta con i loop statements. Guarda l'esempio seguente con un copro del loop vuoto:

+ +
var arr = [1, 2, 3];
+
+// Assegna il valore 0 a tutti gli elementi dell'array
+for (i = 0; i < arr.length; arr[i++] = 0) /* empty statement */ ;
+
+console.log(arr)
+// [0, 0, 0]
+
+ +

Nota: E' una buona pratica commentare l'utilizzo intenzionale di empty statement, poichè non è immediatamente ovvia la differenza con un normale punto e virgola. Nell'esempio seguente l'uso è probabilmente non intenzionale:

+ +
if (condition);       // Attenzione, questo "if" non produce nessun effetto!
+   killTheUniverse()  // E quindi questo sarà eseguito sempre!!!
+
+ +

Un altro Esempio: Un if...else statement senza parentesi graffe ({}). Se three è true, non accadrà nulla, four non viene valutato, e neanche la funzione launchRocket()nel ramo else sarà eseguita.

+ +
if (one)
+  doOne();
+else if (two)
+  doTwo();
+else if (three)
+  ; // nothing here
+else if (four)
+  doFour();
+else
+  launchRocket();
+ +

Specifiche

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ESDraft', '#sec-empty-statement', 'Empty statement')}}{{Spec2('ESDraft')}}
{{SpecName('ES6', '#sec-empty-statement', 'Empty statement')}}{{Spec2('ES6')}}
{{SpecName('ES5.1', '#sec-12.3', 'Empty statement')}}{{Spec2('ES5.1')}}
{{SpecName('ES3', '#sec-12.3', 'Empty statement')}}{{Spec2('ES3')}}
{{SpecName('ES1', '#sec-12.3', 'Empty statement')}}{{Spec2('ES1')}}Initial definition.
+ +

Compatibilità con i Browser

+ + + +

{{Compat("javascript.statements.empty")}}

+ +

See also

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