
Table of Contents
Assignment Operator
The followings are the assignment operator in javascript:
- Simple Assignment
- Additional Assignment
- Subtraction Assignment
- Multiplication Assignment
- Division Assignment
- Reminder Assignment
Simple Assignment (=)
This operator assigns the right operand value to the left operand.
var a='apple', b='banana',c='cat';
Additional Assignment (+=)
This operator adds the value of the right operand to a variable and assigns the result to the left operand.
var x = 10;
x += 5;
//OUTPUT: X will be 15
Subtraction Assignment (-=)
This operator subtracts the value of the right operand from a left operand and assigns the result to the left operand.
var x = 10;
x -= 5;
//OUTPUT: X will be 5
Multiplication Assignment (*=)
This operator multiplies left and right operand values and assigns the result to the left operand.
var x = 10;
x *= 5;
//OUTPUT: X will be 50
Division Operator (/=)
This operator divide left operand value by right operand value and assign the result to the left operand.
var x = 10;
x /= 5;
//OUTPUT: X will be 2
Reminder Operator (%=)
The remainder assignment operator divides a left operand by the value of the right operand and assigns the remainder to the left operand.
var x = 10;
x %= 5;
//OUTPUT: X will be 0