JavaScript assignment operator is equal (=) which assigns the value of the right-hand operand to its left-hand operand. That is if a = b assigns the value of b to a.
The simple assignment operator is used to assign a value to a variable. The assignment operation evaluates the assigned value. Chaining the assignment operator is possible in order to assign a single value to multiple variables.
Operators | Examples | 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 |
data=value
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>JavaScript</title>
<script>
/* Equalto Assignment Operators */
var m = 10;
var n = 3;
o = m + n;
document.write(o);
document.write('<br><br>');
/* Addition Assignment Operators */
var a = 10;
var b = 3;
a += b;
document.write(a);
document.write('<br><br>');
/* Subtraction Assignment Operators */
var m = 10;
var n = 3;
m -= n;
document.write(m);
document.write('<br><br>');
/* Multiplication Assignment Operators */
var p = 10;
var q = 3;
p *= q;
document.write(p);
document.write('<br><br>');
/* Exponentiation Assignment Operators */
var d = 10;
var e = 3;
d **= e;
document.write(d);
document.write('<br><br>');
/* Division Assignment Operators */
var s = 10;
var t = 3;
s /= t;
document.write(s);
document.write('<br><br>');
/* Modulus(Remainder) Assignment Operators */
var x = 10;
var y = 3;
x %= y;
document.write(x);
document.write('<br><br>');
</script>
</head>
<body>
</body>
</html>