diff options
| author | SphinxKnight <SphinxKnight@users.noreply.github.com> | 2021-06-27 15:03:56 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-27 15:03:56 +0200 |
| commit | 9f030ef5fd3a0dc15d94c01d0e1bbd1aba1eed54 (patch) | |
| tree | e6aa6c44ea4c523dbf72464e77745bed1efc8c51 /files/fr/web/javascript/reference/operators/exponentiation | |
| parent | dc9842009bd95e0db7e058a5ebb98f27d6a3f650 (diff) | |
| download | translated-content-9f030ef5fd3a0dc15d94c01d0e1bbd1aba1eed54.tar.gz translated-content-9f030ef5fd3a0dc15d94c01d0e1bbd1aba1eed54.tar.bz2 translated-content-9f030ef5fd3a0dc15d94c01d0e1bbd1aba1eed54.zip | |
Fix #756 by updating the JS operators in fr (#1306)
* Update Operators landing + revamp L10N for 4 operators
* Added NOT / ! -
* +multiplication
* Addition, exponentiation and comparison
* Operateurs de comparaison
* Binary ops
* Missing newline, thx GH UI
* Logical AND / OR
* Assignment ops
* Conflicting clean-up
* Missing EOF newline
* Fix history and redirects
* FIX: fix flaws
* FIX: minox typo fix
* FIX: link flaws
* FIX: fix tags detection
Co-authored-by: tristantheb <tristantheb@gmail.com>
Diffstat (limited to 'files/fr/web/javascript/reference/operators/exponentiation')
| -rw-r--r-- | files/fr/web/javascript/reference/operators/exponentiation/index.html | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/files/fr/web/javascript/reference/operators/exponentiation/index.html b/files/fr/web/javascript/reference/operators/exponentiation/index.html new file mode 100644 index 0000000000..310a21c8fe --- /dev/null +++ b/files/fr/web/javascript/reference/operators/exponentiation/index.html @@ -0,0 +1,95 @@ +--- +title: Exponentiation (**) +slug: Web/JavaScript/Reference/Operators/Exponentiation +tags: + - JavaScript + - Language feature + - Operator + - Reference +browser-compat: javascript.operators.exponentiation +translation-of: Web/JavaScript/Reference/Operators/Exponentiation +--- +<div>{{jsSidebar("Operators")}}</div> + +<p>L'opérateur d'exponentiation (<code>**</code>) fournit le résultat obtenu lorsqu'on élève le premier opérande à la puissance indiquée par le second. Il est équivalent <code>Math.pow</code> exception faite que cet opérateur permet également d'utiliser des valeurs BigInt comme opérandes.</p> + +<div>{{EmbedInteractiveExample("pages/js/expressions-exponentiation.html")}}</div> + +<h2 id="syntax">Syntaxe</h2> + +<pre class="brush: js"> +<strong>Opérateur :</strong> <var>var1</var> ** <var>var2</var> +</pre> + +<h2 id="description">Description</h2> + +<p>L'opérateur d'exponentiation est associatif à droite : <code><var>a</var> ** <var>b</var> ** <var>c</var></code> est équivalent à <code><var>a</var> ** (<var>b</var> ** <var>c</var>)</code>.</p> + +<p>Pour la plupart des langages possédant un opérateur d'exponentiation (ex. PHP, Python, etc.), l'opérateur d'exponentiation possède une précédence plus élevée que les opérateurs unaires (comme l'addition unaire <code>+</code> ou la soustraction unaire <code>-</code>). Il existe toutefois quelques exceptions comme Bash, où <code>**</code> possède une précédence inférieure à celles des opérateurs unaires.</p> + +<p>En JavaScript, il est impossible d'écrire une expression d'exponentiation ambigüe : on ne peut pas placer un opérateur unaire (<code>+/-/~/!/delete/void/typeof</code>) avant le nombre servant de base, cela provoquera une exception <code>SyntaxError</code>.</p> + +<pre class="brush: js"> +-2 ** 2; +// 4 en Bash, -4 pour d'autres langages. +// Invalide en JavaScript car l'opération est ambigüe. + +-(2 ** 2); +// -4 en JavaScript, les parenthèses évitent l'ambiguité. +</pre> + +<p>Attnetion, certains langages de programmation utilisent l'accent circonflexe <kbd>^</kbd> pour exprimer l'exponentiaion mais JavaScript utilise ce symbole pour <a href="/fr/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_XOR">l'opérateur binaire OU exclusif (XOR)</a>.</p> + +<h2 id="examples">Exemples</h2> + +<h3 id="basic_exponentiation">Exponentiation simple</h3> + +<pre class="brush: js"> +2 ** 3 // 8 +3 ** 2 // 9 +3 ** 2.5 // 15.588457268119896 +10 ** -1 // 0.1 +NaN ** 2 // NaN +</pre> + +<h3 id="associativity">Associativité</h3> + +<pre class="brush: js"> +2 ** 3 ** 2 // 512 +2 ** (3 ** 2) // 512 +(2 ** 3) ** 2 // 64</pre> + +<h3 id="usage_with_unary_operators">Avec les opérateurs unaires</h3> + +<p>Pour prendre l'opposé du résultat :</p> + +<pre class="brush: js"> +-(2 ** 2) // -4 +</pre> + +<p>Pour forcer le signe de la base en négatif :</p> + +<pre class="brush: js">(-2) ** 2 // 4 +</pre> + +<h2 id="specifications">Spécifications</h2> + +<p>{{Specifications}}</p> + +<h2 id="browser_compatibility">Compatibilité des navigateurs</h2> + +<p>{{Compat}}</p> + +<h2 id="see_also">Voir aussi</h2> + +<ul> + <li><a href="/fr/docs/Web/JavaScript/Reference/Operators/Addition">Opérateur d'addition</a></li> + <li><a href="/fr/docs/Web/JavaScript/Reference/Operators/Subtraction">Opérateur de soustraction</a></li> + <li><a href="/fr/docs/Web/JavaScript/Reference/Operators/Multiplication">Opérateur de multiplication</a></li> + <li><a href="/fr/docs/Web/JavaScript/Reference/Operators/Division">Opérateur de division</a></li> + <li><a href="/fr/docs/Web/JavaScript/Reference/Operators/Remainder">Opérateur de reste</a></li> + <li><a href="/fr/docs/Web/JavaScript/Reference/Operators/Increment">Opérateur d'incrémentation</a></li> + <li><a href="/fr/docs/Web/JavaScript/Reference/Operators/Decrement">Opérateur de décrémentation</a></li> + <li><a href="/fr/docs/Web/JavaScript/Reference/Operators/Unary_negation">Opérateur de négation unaire</a></li> + <li><a href="/fr/docs/Web/JavaScript/Reference/Operators/Unary_plus">Opérateur plus unaire</a></li> +</ul> |
