diff options
Diffstat (limited to 'files/ca/conflicting/web/javascript/reference/operators/index.html')
-rw-r--r-- | files/ca/conflicting/web/javascript/reference/operators/index.html | 288 |
1 files changed, 0 insertions, 288 deletions
diff --git a/files/ca/conflicting/web/javascript/reference/operators/index.html b/files/ca/conflicting/web/javascript/reference/operators/index.html deleted file mode 100644 index 5f5221c244..0000000000 --- a/files/ca/conflicting/web/javascript/reference/operators/index.html +++ /dev/null @@ -1,288 +0,0 @@ ---- -title: Operadors aritmètics -slug: conflicting/Web/JavaScript/Reference/Operators -translation_of: Web/JavaScript/Reference/Operators -translation_of_original: Web/JavaScript/Reference/Operators/Arithmetic_Operators -original_slug: Web/JavaScript/Referencia/Operadors/Arithmetic_Operators ---- -<div> -<div>{{jsSidebar("Operators")}}</div> -</div> - -<h2 id="Summary" name="Summary">Resum</h2> - -<p><strong>Els operadors aritmètics</strong> prenen valors numèrics (poden ser tant literals com ser variables) com a operands seus i retornen un valor numèric únic. Els operadors aritmètics estàndards són la suma (+), la resta (-), la multiplicació (*), i la divisió (/).</p> - -<h2 id="Suma_()"><a name="Addition">Suma (+)</a></h2> - -<p>L'operador <em>Suma</em> produeix la suma dels operands numèrics o de la concatenació de cadenes.</p> - -<h3 id="Sintaxi">Sintaxi</h3> - -<pre class="syntaxbox"><strong>Operador:</strong> x + y -</pre> - -<h3 id="Exemples">Exemples</h3> - -<pre class="brush: js">// Nombre + Nombre -> suma -1 + 2 // 3 - -// Booleà + Nombre -> suma -true + 1 // 2 - -// Booleà + Booleà -> suma -false + false // 0 - -// Nombre + String -> concatenació -5 + "foo" // "5foo" - -// String + Booleà -> concatenació -"foo" + false // "foofalse" - -// String + String -> concatenació -"foo" + "bar" // "foobar" -</pre> - -<h2 id="Resta_(-)"><a name="Subtraction">Resta (-)</a></h2> - -<p>L'operador <em>resta</em> produeix la resta de dos operands, produint la seva diferència.</p> - -<h3 id="Sintaxi_2">Sintaxi</h3> - -<pre class="syntaxbox"><strong>Operador:</strong> x - y -</pre> - -<h3 id="Exemples_2">Exemples</h3> - -<pre class="brush: js">5 - 3 // 2 -3 - 5 // -2 -"foo" - 3 // NaN</pre> - -<h2 id="Divisió_()"><a name="Division">Divisió (/)</a></h2> - -<p>L'operador divisió produeix el quocient dels seus operands on el operand de l'esquerra és el dividend, i l'operand de la dreta és el divisor.</p> - -<h3 id="Sintaxi_3">Sintaxi</h3> - -<pre class="syntaxbox"><strong>Operador:</strong> x / y -</pre> - -<h3 id="Exemples_3">Exemples</h3> - -<pre class="brush: js">1 / 2 // retorna 0.5 a JavaScript -1 / 2 // retorna 0 in Java -// (cap dels nombres és explícitament n nombre de coma flotant) - -1.0 / 2.0 // retorna 0.5 a JavaScript i Java - -2.0 / 0 // retorna Infinity a JavaScript -2.0 / 0.0 // també retorna Infinity -2.0 / -0.0 // retorna -Infinity a JavaScript</pre> - -<h2 id="Multiplicació_(*)"><a name="Multiplication">Multiplicació (*)</a></h2> - -<p>L'operador <em>multiplicació</em> produeix el producte dels operands.</p> - -<h3 id="Sintaxi_4">Sintaxi</h3> - -<pre class="syntaxbox"><strong>Operador:</strong> x * y -</pre> - -<h3 id="Exemples_4">Exemples</h3> - -<pre class="brush: js">2 * 2 // 4 --2 * 2 // -4 -Infinity * 0 // NaN -Infinity * Infinity // Infinity -"foo" * 2 // NaN -</pre> - -<h2 id="Mòdul_()"><a name="Remainder">Mòdul (%)</a></h2> - -<p>L'operador<em> mòdul </em>retorna el mòdul del primer operand amb el segon, això és, <code>var1</code> modulo <code>var2</code> en la sentència prèvia, on <code>var1</code> i <code>var2 </code>són variables. La funció mòdul és la resta entera de dividir <code>var1</code> <code>per var2</code>. <a href="http://wiki.ecmascript.org/doku.php?id=strawman:modulo_operator" title="http://wiki.ecmascript.org/doku.php?id=strawman:modulo_operator">Hi ha una proposta per a implementar un operador mòdul real en una futura versió de l'ECMAScript.</a></p> - -<h3 id="Sintaxi_5">Sintaxi</h3> - -<pre class="syntaxbox"><strong>Operador:</strong> var1 % var2 -</pre> - -<h3 id="Exemples_5">Exemples</h3> - -<pre class="brush: js">12 % 5 // 2 --1 % 2 // -1 -NaN % 2 // NaN -</pre> - -<h2 id="Increment_()"><a name="Increment">Increment (++)</a></h2> - -<p>L'operador <em>increment</em> incrementa (afegeix un) al seu operand i retorna un valor.</p> - -<ul> - <li>Emprat com a sufix, és a dir, amb l'operador després de l'operand (per exemple: x++), retorna el valor de l'operand abans d'incrementar-lo.</li> - <li>Emprat com a prefix, és a dir, amb l'operador precedint l'operand (per exemple: ++x), retorna el valor de l'operand després d'incrementar-lo.</li> -</ul> - -<h3 id="Sintaxi_6">Sintaxi</h3> - -<pre class="syntaxbox"><strong>Operador:</strong> x++ or ++x -</pre> - -<h3 id="Exemples_6">Exemples</h3> - -<pre class="brush: js">// Sufix -var x = 3; -y = x++; // y = 3, x = 4 - -// Prefix -var a = 2; -b = ++a; // a = 3, b = 3 -</pre> - -<h2 id="Decrement_(--)"><a name="Decrement">Decrement (--)</a></h2> - -<p>L'operador <em>decrement</em> decrementa (resta un) al seu operand i retorna el seu valor.</p> - -<ul> - <li>Emprat com a sufix, és a dir, amb l'operador després de l'operand (per exemple: x--), retorna el valor de l'operand abans de decrementar-lo.</li> - <li>Emprat com a prefix, és a dir, amb l'operador precedint l'operand (per exemple: --x), retorna el valor de l'operand després de decrementar-lo.</li> -</ul> - -<h3 id="Sintaxi_7">Sintaxi</h3> - -<pre class="syntaxbox"><strong>Operador:</strong> x-- or --x -</pre> - -<h3 id="Exemples_7">Exemples</h3> - -<pre class="brush: js">// Sufix -var x = 3; -y = x--; // y = 3, x = 2 - -// Prefix -var a = 2; -b = --a; // a = 1, b = 1 -</pre> - -<h2 id="Negació_unària_(-)"><a name="Unary_negation">Negació unària (-)</a></h2> - -<p>L'operador de negació unària precedeix el seu operand i el nega.</p> - -<h3 id="Sintaxi_8">Sintaxi</h3> - -<pre class="syntaxbox"><strong>Operator:</strong> -x -</pre> - -<h3 id="Exemples_8">Exemples</h3> - -<pre class="brush: js">var x = 3; -y = -x; // y = -3, x = 3 -</pre> - -<h2 id="Operador_unari_de_conversió_a_nombre_()"><a name="Unary_plus">Operador unari de conversió a nombre</a> (+)</h2> - -<p>L'operador unari de conversió a nombre precedeix el seu operand i intenta convertir-lo en un nombre si no ho és ja. Tot i que l'operand de negació unària també pot convertir no-nombres, l'operador de conversió és el mètode més ràpid i recomanat per a convertir quelcom a un nombre ja que no realitza cap altra operació al nombre. Pot convertir cadenes de caràcters representant sencers i nombres en coma flotant, així com els valors <code>true</code>, <code>false</code> i <code>null</code>. Quant a nombres sencers, tant la notació decimal com la hexadecimal (denotada amb el prefixe "0x") estàn suportades. Els nombres negatius també estàn suportats (tot i que no per a hexadecimals). Si no pot interpretar un valor determinat l'operador retornarà<a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN"> NaN</a>.</p> - -<h3 id="Sintaxi_9">Sintaxi</h3> - -<pre class="syntaxbox"><strong>Operador:</strong> +x -</pre> - -<h3 id="Exemples_9">Exemples</h3> - -<pre class="brush: js">+3 // 3 -+"3" // 3 -+true // 1 -+false // 0 -+null // 0 -</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>ECMAScript 1st Edition.</td> - <td>Standard</td> - <td>Initial definition.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-11.6', 'Additive operators')}}<br> - {{SpecName('ES5.1', '#sec-11.5', 'Multiplicative operators')}}<br> - {{SpecName('ES5.1', '#sec-11.3', 'Postfix expressions')}}<br> - {{SpecName('ES5.1', '#sec-11.4', 'Unary operators')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-additive-operators', 'Additive operators')}}<br> - {{SpecName('ES6', '#sec-multiplicative-operators', 'Multiplicative operators')}}<br> - {{SpecName('ES6', '#sec-postfix-expressions', 'Postfix expressions')}}<br> - {{SpecName('ES6', '#sec-unary-operators', 'Unary operators')}}</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 per 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="Vegeu_també">Vegeu també</h2> - -<ul> - <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators">Operadors d'assignació</a></li> -</ul> |