HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Assignment operators assign values to JavaScript variables
Assignment operators assign values to JavaScript variables.
Operator | Example | Same As |
---|---|---|
= | 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 |
The **=
operator is a part of ECMAScript 2016.
The =
assignment operator assigns a value to a variable.
let x = 10;
The +=
assignment operator adds a value to a variable.
let x = 10;
x += 5;
The -=
assignment operator subtracts a value from a variable.
let x = 10;
x -= 5;
The *=
assignment operator multiplies a variable.
let x = 10;
x *= 5;
The /=
assignment divides a variable.
let x = 10;
x /= 5;
The %=
assignment operator assigns a remainder to a variable.
let x = 10;
x %= 5;
Use the correct assignment operator that will result in x
being 15
(same as x = x + y
).
x = 10; y = 5; x y;