From 9f030ef5fd3a0dc15d94c01d0e1bbd1aba1eed54 Mon Sep 17 00:00:00 2001 From: SphinxKnight Date: Sun, 27 Jun 2021 15:03:56 +0200 Subject: 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 --- .../logical_nullish_assignment/index.html | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 files/fr/web/javascript/reference/operators/logical_nullish_assignment/index.html (limited to 'files/fr/web/javascript/reference/operators/logical_nullish_assignment') 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 +--- +
{{jsSidebar("Operators")}}
+ +

L'opérateur d'affectation après coalescence des nuls (x ??= y) effectue une affectation uniquement si l'opérande de gauche (x) vaut null ou undefined.

+ +
{{EmbedInteractiveExample("pages/js/expressions-logical-nullish-assignment.html")}}
+ +

Syntaxe

+ +
+expr1 ??= expr2
+
+ +

Description

+ +

Évaluation en court-circuit

+ +

L'opérateur de coalescence des nuls est évalué de gauche à droite et le moteur teste s'il est possible d'utiliser un court-circuit grâce à la règle suivante :

+ +

(une expression qui renvoie null ou undefined) ?? expr sera court-circuité pour fournir l'opérande gauche si celle-ci ne vaut ni null ni undefined.

+ +

Ce « court-circuit » implique que l'expression expr n'est pas évaluée si ce n'est pas nécessaire. Ainsi, tout effet de bord lié à celle-ci n'aura pas lieu (par exemple, si expr appelle une fonction, cette dernière n'est pas exécutée).

+ +

L'opérateur d'affectation après coalescence des nuls obéit également à cette logique. Ainsi, x ??= y sera équivalent à :

+ +
+x ?? (x = y);
+
+ +

En revanche, ce ne sera pas équivalent à l'expression suivante qui effectue une affectation quoi qu'il arrive :

+ +
+x = x ?? y;
+
+ +

Exemples

+ +

Utiliser l'opérateur d'affectation après coalescence des nuls

+ +
+function config(options) {
+  options.duration ??= 100;
+  options.speed ??= 25;
+  return options;
+}
+
+config({ duration: 125 }); // { duration: 125, speed: 25 }
+config({}); // { duration: 100, speed: 25 }
+
+ +

Spécifications

+ +

{{Specifications}}

+ +

Compatibilité des navigateurs

+ +

{{Compat}}

+ +

Voir aussi

+ + -- cgit v1.2.3-54-g00ecf