aboutsummaryrefslogtreecommitdiff
path: root/files/it/web/javascript/reference/statements/empty/index.html
blob: bb10fd716543fd121c730ada4ee3c88ad3b240cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
---
title: empty
slug: Web/JavaScript/Reference/Statements/Empty
translation_of: Web/JavaScript/Reference/Statements/Empty
---
<div>{{jsSidebar("Statements")}}</div>

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

<div>{{EmbedInteractiveExample("pages/js/statement-empty.html")}}</div>

<p class="hidden">Il sorgente per questo esempio interattivo è immagazzinato in un repository GitHub. Se vuoi contribuire al progeeto degli esempi interattivi, clona <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> e inviaci una pull request.</p>

<h2 id="Sintassi">Sintassi</h2>

<pre class="syntaxbox">;
</pre>

<h2 id="Descrizione">Descrizione</h2>

<p>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<a href="/en-US/docs/Web/JavaScript/Reference/Statements/block"> block statement</a>; esso ne combina diversi in un singolo statement .</p>

<h2 id="Esempi">Esempi</h2>

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

<pre class="brush: js">var arr = [1, 2, 3];

// Assegna il valore 0 a tutti gli elementi dell'array
for (i = 0; i &lt; arr.length; arr[i++] = 0) /* empty statement */ ;

console.log(arr)
// [0, 0, 0]
</pre>

<p><strong>Nota:</strong> 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:</p>

<pre class="brush: js">if (condition);       // Attenzione, questo "if" non produce nessun effetto!
   killTheUniverse()  // E quindi questo sarà eseguito sempre!!!
</pre>

<p>Un altro Esempio: Un <a href="/en-US/docs/Web/JavaScript/Reference/Statements/if...else"><code>if...else</code></a> statement senza parentesi graffe (<code>{}</code>). Se <code>three</code> è <code>true</code>, non accadrà nulla, <code>four</code> non viene valutato, e neanche la funzione <code>launchRocket()</code>nel ramo <code>else</code> sarà eseguita.</p>

<pre class="brush: js">if (one)
  doOne();
else if (two)
  doTwo();
else if (three)
  ; // nothing here
else if (four)
  doFour();
else
  launchRocket();</pre>

<h2 id="Specifiche">Specifiche</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-empty-statement', 'Empty statement')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-empty-statement', 'Empty statement')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-12.3', 'Empty statement')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName('ES3', '#sec-12.3', 'Empty statement')}}</td>
   <td>{{Spec2('ES3')}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName('ES1', '#sec-12.3', 'Empty statement')}}</td>
   <td>{{Spec2('ES1')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Compatibilità_con_i_Browser">Compatibilità con i Browser</h2>



<p>{{Compat("javascript.statements.empty")}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{jsxref("Statements/block", "Block statement")}}</li>
</ul>