diff options
Diffstat (limited to 'files/ca/web/javascript/reference/statements/empty/index.html')
-rw-r--r-- | files/ca/web/javascript/reference/statements/empty/index.html | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/files/ca/web/javascript/reference/statements/empty/index.html b/files/ca/web/javascript/reference/statements/empty/index.html new file mode 100644 index 0000000000..3d3e916fe1 --- /dev/null +++ b/files/ca/web/javascript/reference/statements/empty/index.html @@ -0,0 +1,139 @@ +--- +title: Buida +slug: Web/JavaScript/Reference/Statements/Empty +translation_of: Web/JavaScript/Reference/Statements/Empty +original_slug: Web/JavaScript/Referencia/Sentencies/Buida +--- +<div> +<div>{{jsSidebar("Statements")}}</div> +</div> + +<h2 id="Resum">Resum</h2> + +<p>Una sentència <strong>buida</strong> es fa servir per no proveïr cap sentència, encara que la sintaxi de JavaScript n'esperaria una.</p> + +<h2 id="Sintaxi">Sintaxi</h2> + +<pre class="syntaxbox">; +</pre> + +<h2 id="Descripció">Descripció</h2> + +<p>La sentència buida és un punt i coma (;) que indica que cap sentència s'executarà, encara que la sintaxi de JavaScript en requereixi una. Pel contrari, quan es vol realitzar múltiples sentències, però JavaScript només en permet un, és possible realitzar-ho mitjançant l'ús d'una <a href="/en-US/docs/Web/JavaScript/Reference/Statements/block">sentència de block</a>; que combina diverses sentències en una única sentència.</p> + +<h2 id="Exemples">Exemples</h2> + +<p>La sentència buida sovint s'utilitza amb sentències de bucles. Vegeu l'exemple segúent amb el cos del bucle buit:</p> + +<pre class="brush: js">var arr = [1, 2, 3]; + +// Assign all array values to 0 +for (i = 0; i < arr.length; arr[i++] = 0) /* empty statement */ ; + +console.log(arr) +// [0, 0, 0] +</pre> + +<p><strong>Nota:</strong> És una bona idea comentar l'ús intencional de la sentència buida, ja que no és fa molt obvi diferenciar-lo d'un punt i coma normal. En el següent exemple l'ús probablement no és intencional:</p> + +<pre class="brush: js">if (condition); // Caution, this "if" does nothing! + killTheUniverse() // So this gets always executed!!! +</pre> + +<p>Un altre exemple: Una sentència <a href="/en-US/docs/Web/JavaScript/Reference/Statements/if...else"><code>if...else</code></a> sense claus (<code>{}</code>). Si <code>tres</code> és cert, no passarà res, <u><code>four</code> does not matter, </u>ni tampoc s'executarà la funció <code>launchRocket()</code> en el cas <code>else</code>.</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="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>1a edició de ECMAScript.</td> + <td>Estàndard</td> + <td>Definició inicial.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-12.3', 'Empty statement')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-empty-statement', 'Empty statement')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<p>{{ CompatibilityTable() }}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Característica</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Suport bàsic</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Característica</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Suport bàsic</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="See_also" name="See_also">Vegeu també</h2> + +<ul> + <li>{{jsxref("Statements/block", "Block statement")}}</li> +</ul> |