aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/javascript/reference/operators/remainder/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/es/web/javascript/reference/operators/remainder/index.html')
-rw-r--r--files/es/web/javascript/reference/operators/remainder/index.html83
1 files changed, 83 insertions, 0 deletions
diff --git a/files/es/web/javascript/reference/operators/remainder/index.html b/files/es/web/javascript/reference/operators/remainder/index.html
new file mode 100644
index 0000000000..b8e4540902
--- /dev/null
+++ b/files/es/web/javascript/reference/operators/remainder/index.html
@@ -0,0 +1,83 @@
+---
+title: Resto (%)
+slug: Web/JavaScript/Reference/Operators/Remainder
+translation_of: Web/JavaScript/Reference/Operators/Remainder
+original_slug: Web/JavaScript/Referencia/Operadores/Resto
+---
+<div>{{jsSidebar("Operators")}}</div>
+
+<p>El operador resto (<code>%</code>) devuelve el resto de la división entre dos operandos. Siempre toma el signo del dividendo.</p>
+
+<div>{{EmbedInteractiveExample("pages/js/expressions-remainder.html")}}</div>
+
+<div></div>
+
+<p class="hidden">El código fuente para este ejemplo interactivo se encuentra en un repositorio de GitHub. Si quieres contribuir al proyecto de ejemplos interactivas, por favor clona <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> y realiza un pull request.</p>
+
+<p>Tener en cuenta que en la mayoría de los lenguajes de programación, el operador de resto es ‘%’, pero en otros (como <a href="https://en.wikipedia.org/wiki/Modulo_operation#In_programming_languages">Python, Perl</a>) es el operador módulo. Ambos son iguales para valores positivos, pero cuando el divisor y el dividendo son de signos distintos, se obtienen distintos resultados. Para obtener el módulo en JavaScript, en lugar de <code>a % n</code>, usa <code>((a % n ) + n ) % n</code>.</p>
+
+<h2 id="Sintaxis">Sintaxis</h2>
+
+<pre class="syntaxbox notranslate"><strong>Operador:</strong> <var>var1</var> % <var>var2</var>
+</pre>
+
+<h2 id="Ejemplos">Ejemplos</h2>
+
+<h3 id="Resto_con_dividendo_positivo">Resto con dividendo positivo</h3>
+
+<pre class="brush: js notranslate"> 12 % 5 // 2
+ 1 % -2 // 1
+ 1 % 2 // 1
+ 2 % 3 // 2
+5.5 % 2 // 1.5
+</pre>
+
+<h3 id="Resto_con_dividendo_negativo">Resto con dividendo negativo</h3>
+
+<pre class="brush: js notranslate">-12 % 5 // -2
+-1 % 2 // -1
+-4 % 2 // -0</pre>
+
+<h3 id="Resto_con_NaN">Resto con NaN</h3>
+
+<pre class="brush: js notranslate">NaN % 2 // NaN</pre>
+
+<h3 id="Resto_con_Infinity">Resto con Infinity</h3>
+
+<pre class="brush: js notranslate">Infinity % 2 // NaN
+Infinity % 0 // NaN
+Infinity % Infinity // NaN
+</pre>
+
+<h2 id="Especificaciones">Especificaciones</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Especificación</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-multiplicative-operators', 'Remainder operator')}}</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilidad_con_navegadores">Compatibilidad con navegadores</h2>
+
+
+
+<p>{{Compat("javascript.operators.remainder")}}</p>
+
+<h2 id="Ver_también">Ver también</h2>
+
+<ul>
+ <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Addition">Addition operator</a></li>
+ <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Subtraction">Subtraction operator</a></li>
+ <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Division">Division operator</a></li>
+ <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Multiplication">Multiplication operator</a></li>
+ <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation">Exponentiation operator</a></li>
+ <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Increment">Increment operator</a></li>
+ <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Decrement">Decrement operator</a></li>
+ <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unary_negation">Unary negation operator</a></li>
+ <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unary_plus">Unary plus operator</a></li>
+</ul>