MEILLEUR SITE POUR LES DÉVELOPPEURS WEB

Basic JavaScript

JS Tutorial JS Syntax JS Variables JS Operators JS If Conditions JS Loops JS Strings JS Numbers JS Functions JS Objects JS Dates JS Arrays JS Sets JS Maps JS Math JS RegExp JS Data Types JS Errors JS Debugging JS Events JS Programming JS References JS UTF-8 Characters

JS Advanced

JS Versions JS Functions JS Objects JS Classes JS Iterations JS Promises JS Modules JS HTML DOM JS Windows JS Web API JS AJAX JS JSON JS jQuery JS Graphics JS Examples JS Objects

JavaScript. W3Schools en français. Cours pour débutants

En Ua Es De Ru

JavaScript Affectation


Opérateurs d'affectation JavaScript

Les opérateurs d'affectation attribuent des valeurs aux variables JavaScript.

Opérateur Exemple Identique à
= x = y x = y
+= x += y x = x + y
-= x -= y x = x - y
*= x *= y x = x * y
/= x /= y x = x / y
%= x %= y x = x % y
<<= x <<= y x = x << y
>>= x >>= y x = x >> y
>>>= x >>>= y x = x >>> y
&= x &= y x = x & y
^= x ^= y x = x ^ y
|= x |= y x = x | y
**= x **= y x = x ** y

L'opérateur **= fait partie de ECMAScript 2016.


Exemples de devoirs

L'opérateur d'affectation = affecte une valeur à une variable.

Affectation

let x = 10;
Try it Yourself »

L'opérateur d'affectation += ajoute une valeur à une variable.

Affectation

let x = 10;
x += 5;
Try it Yourself »

L'opérateur d'affectation -= soustrait une valeur d'une variable.

Affectation

let x = 10;
x -= 5;
Try it Yourself »

L'opérateur d'affectation *= multiplie une variable.

Affectation

let x = 10;
x *= 5;
Try it Yourself »

L'affectation /= divise une variable.

Affectation

let x = 10;
x /= 5;
Try it Yourself »

L'opérateur d'affectation %= affecte un reste à une variable.

Affectation

let x = 10;
x %= 5;
Try it Yourself »

Testez-vous avec des exercices

Exercice :

Utilisez l'opérateur d'affectation correct qui donnera comme résultat que x est 15 (identique à x = x + y).

x = 10;
y = 5;
x  y;