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/logical_nullish_assignment | |
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/logical_nullish_assignment')
-rw-r--r-- | files/fr/web/javascript/reference/operators/logical_nullish_assignment/index.html | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/files/fr/web/javascript/reference/operators/logical_nullish_assignment/index.html b/files/fr/web/javascript/reference/operators/logical_nullish_assignment/index.html new file mode 100644 index 0000000000..4860c3558b --- /dev/null +++ b/files/fr/web/javascript/reference/operators/logical_nullish_assignment/index.html @@ -0,0 +1,78 @@ +--- +title: Affectation après coalescence des nuls (??=) +slug: Web/JavaScript/Reference/Operators/Logical_nullish_assignment +tags: + - Assignment operator + - JavaScript + - Language feature + - Logical Operator + - Operator + - Reference +browser-compat: javascript.operators.logical_nullish_assignment +translation-of: Web/JavaScript/Reference/Operators/Logical_nullish_assignment +--- +<div>{{jsSidebar("Operators")}}</div> + +<p>L'opérateur d'affectation après coalescence des nuls (<code>x ??= y</code>) effectue une affectation uniquement si l'opérande de gauche (<code>x</code>) vaut <a href="/fr/docs/Web/JavaScript/Reference/Global_Objects/null"><code>null</code></a> ou <a href="/fr/docs/Web/JavaScript/Reference/Global_Objects/null"><code>undefined</code></a>.</p> + +<div>{{EmbedInteractiveExample("pages/js/expressions-logical-nullish-assignment.html")}}</div> + +<h2 id="syntax">Syntaxe</h2> + +<pre class="brush: js"> +<var>expr1</var> ??= <var>expr2</var> +</pre> + +<h2 id="description">Description</h2> + +<h3 id="short-circuit_evaluation">Évaluation en court-circuit</h3> + +<p>L'opérateur de <a href="/fr/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator">coalescence des nuls</a> est évalué de gauche à droite et le moteur teste s'il est possible d'utiliser un court-circuit grâce à la règle suivante :</p> + +<p><code>(une expression qui renvoie null ou undefined) ?? expr</code> sera court-circuité pour fournir l'opérande gauche si celle-ci ne vaut ni <code>null</code> ni <code>undefined</code>.</p> + +<p>Ce « court-circuit » implique que l'expression <code><var>expr</var></code> <strong>n'est pas évaluée</strong> si ce n'est pas nécessaire. Ainsi, tout effet de bord lié à celle-ci n'aura pas lieu (par exemple, si <code><var>expr</var></code> appelle une fonction, cette dernière n'est pas exécutée).</p> + +<p>L'opérateur d'affectation après coalescence des nuls obéit également à cette logique. Ainsi, <code>x ??= y</code> sera équivalent à :</p> + +<pre class="brush: js"> +x ?? (x = y); +</pre> + +<p>En revanche, ce ne sera pas équivalent à l'expression suivante qui effectue une affectation quoi qu'il arrive :</p> + +<pre class="brush: js example-bad"> +x = x ?? y; +</pre> + +<h2 id="examples">Exemples</h2> + +<h3 id="using_logical_nullish_assignment">Utiliser l'opérateur d'affectation après coalescence des nuls</h3> + +<pre class="brush: js"> +function config(options) { + options.duration ??= 100; + options.speed ??= 25; + return options; +} + +config({ duration: 125 }); // { duration: 125, speed: 25 } +config({}); // { duration: 100, speed: 25 } +</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/Nullish_coalescing_operator">L'opérateur de coalescence des nuls (<code>??</code>)</a></li> + <li><a href="/fr/docs/Glossary/Nullish"><i>Nullish</i></a></li> + <li><a href="/fr/docs/Glossary/Truthy"><i>Truthy</i></a></li> + <li><a href="/fr/docs/Glossary/Falsy"><i>Falsy</i></a></li> +</ul> |